-- SPDX-License-Identifier: GPL-3.0-or-later

local extension = Package:new("new1")
extension.extensionName = "vupslash"
-- extension.game_modes_whitelist = { 'nos_heg_mode', 'new_heg_mode' }
-- dofile "packages/vupslash/game_rule.lua"
dofile "packages/vupslash/aux_skills.lua"

local VslUtil = require "packages/vupslash/util"

Fk:loadTranslationTable{
	--扩展包名及势力
	["vupslash"] = "VUP杀",
	["psp"] = "P-SP",
	["novus"] = "纸片人Novus",
	["usthree"] = "绿野仙踪",
	["facemoe"] = "facemoe",
	["xuyanshe"] = "虚研社",
	["yueshaoshe"] = "月烧社",
	["niya"] = "泥鸭幼儿园",
	["chaociyuan"] = "超次元学院",
	["yuejianchicha"] = "月見喫茶",
	["TheVirkyrie"] = "TheVirkyrie",
	["RainbowPro"] = "虚虹人形",
	["blondel"] = "blondel",
	["vector"] = "vector",
	["keasofer"] = "龙裁司",
	["individual"] = "独立势",
	["bisonpro"] = "仓鼠国",
	["VirtualDove"] = "鸽舍",
	["ciyuanjingxiang"] = "次元镜像",
	["team_fire"] = "火",
	["team_ice"] = "冰",

	--从标包拉来的，后续再确定这东西有啥用
	["black"] = "黑色",
	["red"] = '<font color="#CC3131">红色</font>',
	["nocolor"] = '<font color="grey">无色</font>',
	["heart_char"] = '♥',
	["spade_char"] = '♠',
	["diamond_char"] = '♦',
	["club_char"] = '♣',

	--通用标签
	["@extra_hp"] = "额外体力",
	["@turn_damage"] = "造成伤害",

	--通用选项
	["draw_1"] = "摸一张牌",
	["draw_2"] = "摸两张牌",
	["recover_1"] = "回复一点体力",
	["v_discard_1"] = "弃置一张牌",
	["confirm"] = "确认",
	["cancel"] = "取消",

	--通用描述
	["#defense_damage"] = "由于 %arg”的效果，防止了 %from 对 %to 造成的 %arg2 点伤害",
	["#v_HealHP"] = "%from 回复了 %arg 点体力",
	["#v_overHealHP"] = "%from 的体力回复溢出了 %arg 点",
	["#v_ShowHPAndMaxHP"] = "%from 现在的体力值为 %arg，体力上限为 %arg2",

	--通用技能
	["v_cheat"] = "开挂",
	[":v_cheat"] = "出牌阶段，你可以获得一张想要的牌。",

	--测试用
	["@specified_target-turn"] = "我指定过",
	["@target_specified-turn"] = "指定过我",
}

--------------------------------------------------
--测试技能：超级英姿
--------------------------------------------------
local super_yingzi = fk.CreateTriggerSkill{
  name = "superyingzi",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = data.n + 20
  end,
}

--------------------------------------------------
--测试技能：摸指定牌
--------------------------------------------------

local v_cheat = fk.CreateActiveSkill{
  name = "v_cheat",
  anim_type = "drawcard",
  can_use = function(self, player)
    return true
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local cardTypeName = room:askForChoice(from, { 'basic', 'trick', 'equip' }, "cheat")
    local cardType = Card.TypeBasic
    if cardTypeName == 'trick' then
      cardType = Card.TypeTrick
    elseif cardTypeName == 'equip' then
      cardType = Card.TypeEquip
    end

    local allCardIds = Fk:getAllCardIds()
    local allCardMapper = {}
    local allCardNames = {}
    for _, id in ipairs(allCardIds) do
      local card = Fk:getCardById(id)
      if card.type == cardType then
        if allCardMapper[card.name] == nil then
          table.insert(allCardNames, card.name)
        end

        allCardMapper[card.name] = allCardMapper[card.name] or {}
        table.insert(allCardMapper[card.name], id)
      end
    end

    if #allCardNames == 0 then
      return
    end

    local cardName = room:askForChoice(from, allCardNames, "cheat")
    local toGain = nil
    if #allCardMapper[cardName] > 0 then
      toGain = allCardMapper[cardName][math.random(1, #allCardMapper[cardName])]
    end

    from:addToPile(self.name, toGain, true, self.name)
    room:obtainCard(effect.from, toGain, true, fk.ReasonPrey)
  end
}

--------------------------------------------------
--测试技能：流失体力
--------------------------------------------------

local v_lose = fk.CreateActiveSkill{
  name = "v_lose",
  anim_type = "offensive",
  can_use = function(self, player)
    return true
  end,
  target_num = 1,
  -- card_num = 1,
  card_filter = function(self, to_select, selected, selected_targets)
    return false
    -- if #selected == 1 then return false end
    -- return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  target_filter = function(self, to_select, selected)
    -- local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:loseHp(target, 1, self.name)
  end,
}

--------------------------------------------------
--嗜甜
--------------------------------------------------

local v_shitian = fk.CreateTriggerSkill{
  name = "v_shitian",
  --默认播放配音，可以通过Mute=false关闭技能配音。
  --mute = true,
  --赋予支援型技能定义
  anim_type = "support", 
  --时机：阶段开始时
  events = {fk.EventPhaseStart}, 
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能、遍历到的角色处于准备阶段。
  can_trigger = function(self, event, target, player, data) 
    return target == player and player:hasSkill(self.name) and
      player.phase == Player.Start
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  -- on_cost = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   return true
  --   --end
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --播放技能语音
    room:broadcastSkillInvoke(self.name)
    local judge = {} ---@type JudgeStruct
    judge.who = player
    --这一条的意思是，出现以下两种花色条件后显示判定成功的特效
    judge.pattern = ".|.|heart,diamond"
    judge.reason = self.name
    room:judge(judge)

    if judge.card.color == Card.Red then
      player:drawCards(1, self.name)
      --考虑到本作存在治疗过量概念，不需要角色受伤也可触发回复效果。
      --if player:isWounded() then 
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
      --彩蛋标签准备
      room:setPlayerMark(player, "v_shitian_failed", 0)
      room:delay(500)
    else  --触发彩蛋
      if player:getMark("v_shitian_failed") >= 1 then
        room:setEmotion(player, "./packages/vupslash/image/anim/v_shitian_failed")

      else
        room:addPlayerMark(player, "v_shitian_failed", 1)
      end
    end
  end,
}

--------------------------------------------------
--藏聪
--------------------------------------------------

local v_cangcong = fk.CreateTriggerSkill{
  name = "v_cangcong",
  --赋予防御型技能定义
  anim_type = "defensive",
  --时机：目标确定后
  events = {fk.TargetConfirmed},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能、牌的种类为杀/锦囊牌、牌的目标>1。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and
      (data.card.name == "slash" or (data.card.type == Card.TypeTrick and
      data.card.sub_type ~= Card.SubtypeDelayedTrick)) and
      #AimGroup:getAllTargets(data.tos) > 1
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  -- on_cost = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   return true
  --   --end
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setEmotion(player, "./packages/vupslash/image/anim/skill_nullify")
    table.insert(data.nullifiedTargets, player.id)
  end,
}

--------------------------------------------------
--绫奈奈奈
--------------------------------------------------

local lingnainainai_fentujk = General(extension, "lingnainainai_fentujk", "psp", 3, 3, General.Female)
lingnainainai_fentujk:addSkill(v_shitian)
lingnainainai_fentujk:addSkill(v_cangcong)

Fk:loadTranslationTable{
	["lingnainainai_fentujk"] = "绫奈奈奈",
	["&lingnainainai_fentujk"] = "绫奈奈奈",
	["#lingnainainai_fentujk"] = "粉兔JK",
	["$lingnainainai_fentujk"] = "萌新",
	["designer:lingnainainai_fentujk"] = "NSX",
	["cv:lingnainainai_fentujk"] = "",
	["illustrator:lingnainainai_fentujk"] = "",
	["~lingnainainai_fentujk"] = "",
	["v_shitian"] = "嗜甜",
	[":v_shitian"] = "准备阶段，你可以<font color='#A9A9A9'>发动此技能</font>，进行一次判定，若结果为红，你摸一张牌并回复一点体力。",
	["v_cangcong"] = "藏聪",
	[":v_cangcong"] = "你成为【杀】或普通锦囊牌的目标后，若此牌目标数＞1，你可以发动此技能令此牌对你无效。",
}

--------------------------------------------------
--抽卡
--技能马克：解锁隐藏巫女豹与戦的代码；
--------------------------------------------------

local v_chouka = fk.CreateTriggerSkill{
  name = "v_chouka",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
  --时机：阶段开始时
  events = {fk.EventPhaseStart},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能、遍历到的角色处于摸牌阶段。
  can_trigger = function(self, event, target, player, data)
    return (target == player and player:hasSkill(self.name) and player.phase == Player.Draw)
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  -- on_cost = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   return true
  --   --end
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --记录已判定的花色
    local used_suit = {}
    local used_suit_show = {}
    local dummy = Fk:cloneCard('slash', Card.NoSuit, 0)
    while true do
      local all_suit = {"spade", "heart", "club", "diamond"}
      for _, s in ipairs(used_suit) do table.removeOne(all_suit, s) end
      local pattern = ".|.|" .. (#all_suit == 0 and "none" or table.concat(all_suit, ","))
      local judge = {
        who = player,
        reason = self.name,
        pattern = pattern,
      }
      room:judge(judge)
      local suit = judge.card:getSuitString()
      -- local suit_show = judge.card:getSuitString() .. "_char"
      if table.contains(used_suit, suit) then
        return true
      else
        table.insert(used_suit, suit)
        table.insert(used_suit_show, VslUtil.card_suits_table[suit])
        dummy:addSubcard(judge.card)
      end
      local prompt_suit = table.concat(used_suit_show, "+")
      -- local prompt_suit = used_suit_show
      local prompt = "v_chouka_choice_log:::"..prompt_suit
      -- local prompt = "v_chouka_choice_log1+"..prompt_suit.."+v_chouka_choice_log2"
      local choices = {"v_chouka_repeat", "v_chouka_stop"}
      local choice = room:askForChoice(player, choices, self.name, prompt)
      --点击取消，退出判定。
      if choice == "v_chouka_stop" then
        room:obtainCard(player.id, dummy, true)
        if #(dummy.subcards) >= 3 then
          room:setEmotion(player, "./packages/vupslash/image/anim/haibao")
          --getThread暂无此代码，因此先注释掉。
          room:delay(360)
          room:setEmotion(player, "./packages/vupslash/image/anim/haibao")
          if #(dummy.subcards) >= 4 then
            --为玩家记录可解锁角色，由于暂无本功能，先注释掉
            --RecordUnlockGenerals(player, "baishenyao_weiwunv")
            room:delay(360)
            room:setEmotion(player, "./packages/vupslash/image/anim/haibao")
            room:delay(360)
            room:setEmotion(player, "./packages/vupslash/image/anim/haibao")
          end
        end
        room:delay(500)
        break
      end
    end
  end,
}

--------------------------------------------------
--慵懒
--------------------------------------------------

local v_yonglanHelper = fk.CreateTriggerSkill{
  name = "#v_yonglanHelper",
  refresh_events = {fk.TargetConfirming},
  can_refresh = function(self, event, target, player, data)
    --print(data.card.number)
    return (target == player and player:hasSkill(self.name))
  end,
  on_refresh = function(self, event, target, player, data)
    local card = data.card
    local room = player.room
    if card.trueName == "slash" and card.number > 0 and card.id > 0 then
      --print(card.number)
      room:setPlayerMark(player, "v_yonglan_currentSlash", card.number)
    else
      room:setPlayerMark(player, "v_yonglan_currentSlash", 999)
    end
  end
}
local v_yonglan = fk.CreateViewAsSkill{
  name = "v_yonglan",
  anim_type = "defensive",
  pattern = "jink",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).number > Self:getMark("v_yonglan_currentSlash")
      and Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("jink")
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
  end,
}
v_yonglan:addRelatedSkill(v_yonglanHelper)

--------------------------------------------------
--白神遥
--角色马克：抽卡
--------------------------------------------------

local baishenyao_zhaijiahaibao = General(extension, "baishenyao_zhaijiahaibao", "psp", 3, 3, General.Female)
baishenyao_zhaijiahaibao:addSkill(v_chouka)
baishenyao_zhaijiahaibao:addSkill(v_yonglan)

Fk:loadTranslationTable{
	["baishenyao_zhaijiahaibao"] = "白神遥",
	["&baishenyao_zhaijiahaibao"] = "白神遥",
	["#baishenyao_zhaijiahaibao"] = "宅家海豹",
	["$baishenyao_zhaijiahaibao"] = "简单",
	["designer:baishenyao_zhaijiahaibao"] = "NSX",
	["cv:baishenyao_zhaijiahaibao"] = "",
	["illustrator:baishenyao_zhaijiahaibao"] = "Bison仓鼠",
	["~baishenyao_zhaijiahaibao"] = "我不玩啦！",
	["v_chouka"] = "抽卡",
	[":v_chouka"] = "摸牌阶段开始时，你可以发动此技能，进行判定，若你本次“抽卡”的所有判定结果花色均不同，" ..
		"则你选择一项：1.重复此流程 2.获得这些判定牌；否则你结束本阶段。",
	["v_chouka_stop"] = "获得所有判定牌",
	["v_chouka_repeat"] = "继续进行判定",
	["v_chouka_choice_log"] = "目前累积的花色： %arg \n继续判定若花色重复则结束摸牌阶段",
	-- ["v_chouka_choice_log1"] = "目前累积的花色： ",
	-- ["v_chouka_choice_log2"] = "\n继续判定若花色重复则结束摸牌阶段",
	["v_yonglan"] = "慵懒",
	[":v_yonglan"] = "每回合限一次，你需要使用【闪】响应【杀】时，你可以将一张点数大于此【杀】的手牌当【闪】使用。",
}

--------------------------------------------------
--礼崩
--FIXME:礼崩失败后还能用杀。
--TODO:礼崩禁止使用杀是否需要技能存在待定，看起来不需要
--------------------------------------------------

local v_libeng_prohibit = fk.CreateProhibitSkill{
  name = "#v_libeng_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("v_libeng_prohibit_slash-phase") > 0 
      and card.trueName == "slash"
  end,
}
local v_libeng_buff = fk.CreateTargetModSkill{
  name = "#v_libeng_buff",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self.name) and skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase and player:getMark("@v_libeng") > 0 then
      return 999
    end
  end,
}
local v_libeng_slash = fk.CreateTriggerSkill{
  name = "#v_libeng_slash",
  --赋予输出型技能定义,
  anim_type = "offensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：目标确定后
  events = {fk.TargetSpecified},
  --触发条件：触发时机的角色为遍历到的角色，触发者拥有此技能，牌的真名为杀，遍历到的角色存在礼崩胜利标记
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) 
    and data.card.trueName == "slash" and player:getMark("@v_libeng") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@v_libeng", 1)
    data.disresponsive = true
  end,
}
local v_libeng = fk.CreateActiveSkill{
  name = "v_libeng",
  anim_type = "offensive",
  --如何检查自己是否可以拼点？
  can_use = function(self, player)
    return (not player:isKongcheng()) and player:getMark("v_libeng_prohibit_skill-phase") == 0 
  end,
  target_num = 1,
  -- card_num = 1,
  card_filter = function(self, to_select, selected, selected_targets)
    return false
    -- if #selected == 1 then return false end
    -- return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  --如何检查对方是否可以被拼点？
  target_filter = function(self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and to_select ~= Self.id and (not target:isKongcheng())
  end,
  on_use = function(self, room, effect)
    --先拼点
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    --根据结果提供对应mark
    if pindian.results[target.id].winner == player then
      room:addPlayerMark(player, "@v_libeng", 1)
    else
      room:addPlayerMark(player, "v_libeng_prohibit_skill-phase", 1)
      room:addPlayerMark(player, "v_libeng_prohibit_slash-phase", 1)
    end
  end,
}

v_libeng:addRelatedSkill(v_libeng_buff)
v_libeng:addRelatedSkill(v_libeng_prohibit)
v_libeng:addRelatedSkill(v_libeng_slash)

--------------------------------------------------
--超度
--TODO：到时候把技能失效补好。
--------------------------------------------------

local v_chaodu = fk.CreateTriggerSkill{
  name = "v_chaodu",
  anim_type = "support",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self.name, false, false) and not player.dead
      and data.damage 
      and data.damage.card and data.damage.card.trueName == "slash" 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choiceList = {}
    if player:isWounded() then 
      table.insert(choiceList, "recover_1")
    end
    table.insert(choiceList, "draw_2")
    table.insert(choiceList, "v_chaodu_counter")
    table.insert(choiceList, "cancel")
    local choice = room:askForChoice(player, choiceList, self.name)
    if choice == "cancel" then
      return false
    elseif choice == "recover_1" then
      self.cost_data = 1
    elseif choice == "draw_2" then
      self.cost_data = 2
    -- elseif choice == "v_chaodu_counter" then
    --   self.cost_data = 3
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == 1 then
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
    elseif self.cost_data == 2 then
      player:drawCards(2, self.name)
    -- elseif self.cost_data == 3 then
    --   print("to be continued")
    end
  end,
}

--------------------------------------------------
--秋凛子
--角色马克：
--------------------------------------------------

local qiulinzi_wangyinwunv = General(extension, "qiulinzi_wangyinwunv", "psp", 4, 4, General.Female)
qiulinzi_wangyinwunv:addSkill(v_libeng)
qiulinzi_wangyinwunv:addSkill(v_chaodu)

Fk:loadTranslationTable{
	["qiulinzi_wangyinwunv"] = "秋凛子",
	["&qiulinzi_wangyinwunv"] = "秋凛子",
	["#qiulinzi_wangyinwunv"] = "网瘾巫女",
	["$qiulinzi_wangyinwunv"] = "简单",
	["designer:qiulinzi_wangyinwunv"] = "NSX",
	["cv:qiulinzi_wangyinwunv"] = "",
	["illustrator:qiulinzi_wangyinwunv"] = "Bison仓鼠",
	["~qiulinzi_wangyinwunv"] = "",
	["v_libeng"] = "礼崩",
	["#v_libeng_prohibit"] = "礼崩",
	["#v_libeng_buff"] = "礼崩",
	["#v_libeng_slash"] = "礼崩",
	["@v_libeng"] = "礼崩",
	[":v_libeng"] = "出牌阶段，你可以与一名角色拼点：若你赢，你使用的下一张【杀】无次数限制且不能被【闪】响应；若你没赢，本阶段你不能使用【杀】、不能发动此技能。",
	["$v_libeng"] = "",
	["^v_libeng"] = "操作提示：<br/>选择一张用于拼点的手牌→选择一名角色→确定",
	["v_chaodu"] = "超度",
	--[":chaodu"] = "你造成伤害使一名角色离场时，你可以摸两张牌、将其武将牌替换为秋凛子Token（无技能）。",
	[":v_chaodu"] = "当一名其他角色因受到【杀】的伤害而离场时，你可以<font color='#A9A9A9'>发动此技能</font>，选择一项：1.摸两张牌；2.回复1点体力。",
	-- [":v_chaodu"] = "当一名其他角色因受到【杀】的伤害而离场时，你可以<font color='#A9A9A9'>发动此技能</font>，选择一项：1.摸两张牌；2.回复1点体力；3.令其技能失效。",
	["$v_chaodu1"] = "",
	["$v_chaodu2"] = "",
	-- ["v_chaodu_draw"] = "摸两张牌",
	-- ["v_chaodu_recover"] = "回复1点体力",
	["v_chaodu_counter"] = "令离场者技能失效",
}

--------------------------------------------------
--卓识
--------------------------------------------------

local v_zhuoshi_card = fk.CreateActiveSkill{
  name = "#v_zhuoshi_card",
  anim_type = "drawcard",
  min_target_num = function(self)
    if self.interaction.data == "v_zhuoshi_give_card" then
      return 1
    elseif self.interaction.data == "v_discard_1" then
      return 0
    end
  end,
  max_target_num = 1,
  min_card_num = 1,
  interaction = function(self)
    local types = Self:getMark("v_zhuoshi-turn")
    local v_zhuoshi_choice = {"v_discard_1"}
    if type(types) ~= "table" or #types < 3 then
      table.insert(v_zhuoshi_choice, "v_zhuoshi_give_card")
    end
    return UI.ComboBox {
      choices = v_zhuoshi_choice
    } 
  end,
  can_use = function(self, player)
    return player:isAlive() and not player:isNude()
  end,
  card_filter = function(self, to_select, selected, targets)
    if self.interaction.data == "v_zhuoshi_give_card" then
      local types = Self:getMark("v_zhuoshi-turn")
      local card_or_not = true
      for _,p in ipairs(selected) do
        if Fk:getCardById(p).type == Fk:getCardById(to_select).type then
          card_or_not = false
          break
        end
      end
      if type(types) == "table" then
        return card_or_not and not table.contains(types, Fk:getCardById(to_select):getTypeString())
      else
        return card_or_not
      end
    elseif self.interaction.data == "v_discard_1" then
      return #selected == 0 and ( not Self:prohibitDiscard(Fk:getCardById(to_select)) )
    end
  end,
  target_filter = function(self, to_select, selected, cards)
    if self.interaction.data == "v_zhuoshi_give_card" then
      return #selected == 0 and to_select ~= Self.id
    elseif self.interaction.data == "v_discard_1" then
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = nil
    -- 如果存在目标，则为交牌；否则必定为弃牌。
    if effect.tos[1] then
      target = room:getPlayerById(effect.tos[1])
      local types = player:getMark("v_zhuoshi-turn")
      local types_show = player:getMark("@v_zhuoshi_show-turn")
      -- 更新已经交出去的牌的标记
      if type(types) ~= "table" then
        types = {}
      end
      for _,p in ipairs(effect.cards) do
        table.insertIfNeed(types, Fk:getCardById(p):getTypeString())
      end
      --刷新显示用标记
      types_show = {}
      if table.contains(types, "basic") then
        table.insert(types_show, VslUtil.short_card_type["basic"])
      end
      if table.contains(types, "trick") then
        table.insert(types_show, VslUtil.short_card_type["trick"])
      end
      if table.contains(types, "equip") then
        table.insert(types_show, VslUtil.short_card_type["equip"])
      end
      --设定标记
      room:setPlayerMark(player, "v_zhuoshi-turn", types)
      room:setPlayerMark(player, "@v_zhuoshi_show-turn", types_show)
      --交牌
      room:moveCards({
        ids = effect.cards,
        from = player.id,
        to = target.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonGive,
      })
    else
      --弃牌
      room:moveCards({
        ids = effect.cards,
        from = player.id,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonDiscard,
      })
    end
  end,
}
local v_zhuoshi = fk.CreateTriggerSkill{
  name = "v_zhuoshi",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：宣告手牌使用时
  events = {fk.AfterCardUseDeclared},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能
  --         牌的类型为锦囊牌
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) 
    and data.card.type == Card.TypeTrick
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,

  on_use = function(self, event, target, player, data)
    local room = player.room
    local types = player:getMark("v_zhuoshi-turn")
    local bas = 0
    local tri = 0
    local equ = 0
    if type(types) == "table" then
      if table.contains(types, "basic") then
        bas = 1
      end
      if table.contains(types, "trick") then
        tri = 1
      end
      if table.contains(types, "equip") then
        equ = 1
      end
    end
    local next_str = ""
    local type_str = "v_zhuoshi_type_" .. (bas + tri*2 + equ*4)
    if type_str ~= "v_zhuoshi_type_7" then
      next_str = "v_zhuoshi_can_give"
    end
    local prompt = "#v_zhuoshi_cardask:::"..next_str..":"..type_str
    player:drawCards(1, self.name)
    room:askForUseActiveSkill(player, "#v_zhuoshi_card", prompt, false)
  end,
}

v_zhuoshi:addRelatedSkill(v_zhuoshi_card)

--------------------------------------------------
--法棍
--技能马克：伪实现写好了，完全实现还需要一些时间。
--------------------------------------------------

local v_fagun = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_fagun",
  --(非必要）赋予防御型技能定义
  anim_type = "defensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：卡牌移动后，受到伤害时
  events = {fk.AfterCardsMove, fk.DamageInflicted},
  --触发条件：
  -- 卡牌移动后：
  --  触发时机的角色为遍历到的角色、遍历到的角色具有本技能、
  --  遍历到的角色不处于notactive状态、
  --  牌的移动来源存在且为遍历到的角色、牌移动原因为弃置
  --  检索牌堆后，发现存在红色基本牌
  --  不存在特定标记。
  -- 受到伤害时：
  --  触发时机的角色为遍历到的角色、遍历到的角色具有本技能、
  --  造成的伤害大于0、存在牌、牌的颜色为红色、
  --  存在特定标记。
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      if player:hasSkill(self.name) and player:getMark("@@v_fagun_effect") == 0 then
        for _, move in ipairs(data) do
          if move.from and move.from == player.id and move.moveReason == fk.ReasonDiscard and player.phase ~= Player.NotActive then
            for _, info in ipairs(move.moveInfo) do
              local dis_card = Fk:getCardById(info.cardId)
              if dis_card:getColorString() == "red" and dis_card.type == Card.TypeBasic then
                return true
              end
            end
          end
        end
      end
    elseif event == fk.DamageInflicted then
      return target == player and player:hasSkill(self.name) 
        and data.damage > 0 and data.card and data.card.color == Card.Red 
        and player:getMark("@@v_fagun_effect") ~= 0
    end
  end,
  --使用流程：
  -- 卡牌移动后：
  --   为遍历到的角色提供特定标记
  -- 受到伤害时：
  --  return true
  on_use = function(self, event, target, player, data)
    --遍历全场所有存活角色，挑出其中未被横置的角色。
    local room = player.room
    if event == fk.AfterCardsMove then
      room:setPlayerMark(player, "@@v_fagun_effect", 1)
    elseif event == fk.DamageInflicted then
      return true
    end
  end,

  -- 由于标记类型特殊，在eventphasechanging需要刷新标签。
  -- 触发时机：from为notacitve；to不为notactive；存在特定标记。
  refresh_events = {fk.EventPhaseChanging},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@v_fagun_effect") ~= 0 
      and data.from == Player.NotActive and data.to ~= Player.NotActive
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@v_fagun_effect", 0)
  end,
}

--------------------------------------------------
--YY
--角色马克：
--------------------------------------------------

local yizhiyy_mianbaoren = General(extension, "yizhiyy_mianbaoren", "psp", 4, 4, General.Male)
yizhiyy_mianbaoren:addSkill(v_zhuoshi)
yizhiyy_mianbaoren:addSkill(v_fagun)

Fk:loadTranslationTable{
	["yizhiyy_mianbaoren"] = "亦枝YY",
	["&yizhiyy_mianbaoren"] = "亦枝YY",
	["#yizhiyy_mianbaoren"] = "面包人",
	["$yizhiyy_mianbaoren"] = "进阶",
	["designer:yizhiyy_mianbaoren"] = "NSX",
	["cv:yizhiyy_mianbaoren"] = "",
	["illustrator:yizhiyy_mianbaoren"] = "",
	["~yizhiyy_mianbaoren"] = "",
	["v_zhuoshi"] = "卓识",
	["#v_zhuoshi_card"] = "卓识",
	["@v_zhuoshi_show-turn"] = "卓识",
	[":v_zhuoshi"] = "锁定技，你使用锦囊牌时，你摸一张牌，然后弃置一张牌或将任意张牌交给一名其他角色。<br/>以此法交出的牌每回合每种类型限一张。",
	["$v_zhuoshi"] = "",
	["v_zhuoshi_give_card"] = "交给一名角色任意张牌",
	["#v_zhuoshi_carddis"] = "若你选择弃置一张牌，你须弃置一张牌",
	["#v_zhuoshi_cardaskgive"] = "若你选择交给其他角色一张牌，你可将任意张类别不同的牌交给一名角色<br/>你可以交出 %arg",
	["#v_zhuoshi_cardask"] = "你须弃置一张牌%arg%arg2",
	["v_zhuoshi_can_give"] = "，或将任意张类别不同的牌交给一名角色<br/>你可以交出 ",
	["v_zhuoshi_type_0"] = "基本牌、锦囊牌、装备牌",
	["v_zhuoshi_type_1"] = "锦囊牌、装备牌",
	["v_zhuoshi_type_2"] = "基本牌、装备牌",
	["v_zhuoshi_type_3"] = "装备牌",
	["v_zhuoshi_type_4"] = "基本牌、锦囊牌",
	["v_zhuoshi_type_5"] = "锦囊牌",
	["v_zhuoshi_type_6"] = "基本牌",
	["v_zhuoshi_type_7"] = "",
	["~v_zhuoshi"] = "<br/>交出：选择若干张牌→选择一名角色→确定<br/>弃置：选择一张牌→确定",
	["v_fagun"] = "法棍",
	--[":fagun"] = "锁定技，弃牌阶段，若你弃置了红色基本牌，则直到你的下回合开始前，防止你受到的红色牌造成的伤害。",
	[":v_fagun"] = "锁定技，若你于回合内弃置了红色基本牌，则直到你的下回合开始前，防止你受到的红色牌造成的伤害。",
	["$v_fagun"] = "",
	["@@v_fagun_effect"] = "法棍护法中",
}

--------------------------------------------------
--逐猎
--------------------------------------------------

local v_zhulie = fk.CreateTargetModSkill{
  name = "v_zhulie",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self.name) 
      and card
      and card.color == Card.Red 
      and scope == Player.HistoryPhase then
      return 999
    end
  end,
  distance_limit_func =  function(self, player, skill, card)
    if player:hasSkill(self.name) 
      and card
      and card.color == Card.Black then
      return 999
    end
  end,
}

--------------------------------------------------
--混音
--------------------------------------------------

local v_hunyin = fk.CreateTriggerSkill{
  name = "v_hunyin",
  --赋予进攻型技能定义
  anim_type = "offensive",
  --时机：阶段开始时，目标指定后
  events = {fk.EventPhaseStart, fk.TargetSpecified},
  --触发条件：(已完成)
  --（阶段开始时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              被遍历到的角色处于回合开始阶段；
  --              牌堆中的牌>=2张；
  --（目标指定时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              遍历到的角色具有某种标记。
  --              使用的牌为杀
  --              本次流程中第一次触发这个时机
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self.name)
      and player.phase == Player.Start
      and #room.draw_pile >= 2
    elseif event == fk.TargetSpecified then
      return target == player and player:hasSkill(self.name)
      and player:getMark("@@v_hunyin_buff-turn") > 0
      and data.card.trueName == "slash"
      and data.firstTarget
    end
  end,
  on_cost = function(self, event, target, player, data)
    --确认是否发动技能。
    if event == fk.EventPhaseStart then
      local room = player.room
      if room:askForSkillInvoke(player, self.name, data) then
        return true
      end
    --满足技能发动要求后，锁定发动。
    elseif event == fk.TargetSpecified then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      --牌堆顶展示两张牌。【完成】
      local ids = {}
      for i = 1, 2, 1 do
        table.insert(ids, room.draw_pile[i])
      end
      player:showCards(ids)
      --比较两张牌的颜色，根据颜色决定是否增加BUFF标记。【完成】
      if Fk:getCardById(ids[1]).color ~= Fk:getCardById(ids[2]).color then
        room:addPlayerMark(player, "@@v_hunyin_buff-turn", 1)
        room:sendLog{
          type = "#v_hunyin_log",
          from = player.id,
          arg = self.name,
          arg2 = "v_hunyin_different",
        }
      elseif Fk:getCardById(ids[1]).color == Fk:getCardById(ids[2]).color then
        room:sendLog{
          type = "#v_hunyin_log",
          from = player.id,
          arg = self.name,
          arg2 = "v_hunyin_same",
        }
      end
      --询问是否弃牌。【完成】
      local prompt = "v_hunyin_throw_choice"
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        room:throwCard(ids, self.name, player, player)
        room:sendLog{
          type = "#v_hunyin_throw_log",
          from = player.id,
          arg = 2,
        }
      end
    --你使用的【杀】不可被【闪】响应【完成】
    elseif event == fk.TargetSpecified then
      data.disresponsive = true
    end
  end,
}

--------------------------------------------------
--莲汰
--------------------------------------------------

local liantai_bingyuanlangwang = General(extension, "liantai_bingyuanlangwang", "psp", 4, 4, General.Male)
liantai_bingyuanlangwang:addSkill(v_zhulie)
liantai_bingyuanlangwang:addSkill(v_hunyin)

Fk:loadTranslationTable{
	["liantai_bingyuanlangwang"] = "莲汰",
	["&liantai_bingyuanlangwang"] = "莲汰",
	["#liantai_bingyuanlangwang"] = "冰原狼王",
	["$liantai_bingyuanlangwang"] = "简单",
	["designer:liantai_bingyuanlangwang"] = "NSX",
	["cv:liantai_bingyuanlangwang"] = "",
	["illustrator:liantai_bingyuanlangwang"] = "",
	["~liantai_bingyuanlangwang"] = "",
	["v_zhulie"] = "逐猎",
	[":v_zhulie"] = "锁定技，你使用红色牌无次数限制，你使用黑色牌无距离限制。",
	["$v_zhulie"] = "",
	["v_hunyin"] = "混音",
	[":v_hunyin"] = "准备阶段，你可以<font color='#A9A9A9'>发动此技能</font>，展示<font color='#9400D3'>牌堆顶的两张牌</font>，可以将<font color='#9400D3'>之</font>置入弃牌堆。若<font color='#9400D3'>这些牌</font>颜色不同，本回合你使用的【杀】不能被【闪】响应。",
	["$v_hunyin"] = "",
	["@@v_hunyin_buff-turn"] = "混音",
	--[":mark:&hunyin_buff"] = "本回合使用的【杀】不能被【闪】响应",
	["v_hunyin_throw"] = "混音",
	["v_hunyin_throw_choice"] = "你可以将展示的牌置入弃牌堆",
	["#v_hunyin_throw_log"] = "%from 将 %arg 张牌置入弃牌堆",
	["v_hunyin_different"] = "颜色不同",
	["v_hunyin_same"] = "颜色相同",
	["#v_hunyin_log"] = "%from 的“%arg”展示结果为：%arg2",
}

--------------------------------------------------
--薄纱
--------------------------------------------------

local v_baosha_prohibit = fk.CreateProhibitSkill{
  name = "#v_baosha_prohibit",
  is_prohibited = function(self, from, to, card)
    if to:hasSkill("v_baosha") then
      return true
    end
  end,
}
local v_baosha = fk.CreateTriggerSkill{
  name = "v_baosha",
  --赋予防御型技能定义
  anim_type = "defensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：阶段变化时
  events = {fk.EventPhaseChanging},
  --触发条件：
  --触发时机的角色为遍历到的角色、遍历到的角色具有本技能；
  --上一阶段为不活跃阶段，下一阶段不为不活跃阶段。
  can_trigger = function(self, event, target, player, data)
    local change = data
    return target == player and player:hasSkill(self.name) 
    and change.from == Player.NotActive and change.to ~= Player.NotActive
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  -- on_cost = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   return true
  --   --end
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-v_baosha", nil, true)
  end,
}

v_baosha:addRelatedSkill(v_baosha_prohibit)

--------------------------------------------------
--衔尾
--------------------------------------------------

local v_xianwei = fk.CreateViewAsSkill{
  name = "v_xianwei",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
  pattern = "ex_nihilo",
  card_filter = function(self, to_select, selected)
    local room = Fk:currentRoom()
    local pls = room.players
    local pp = nil
    --通过是否处于出牌阶段确认是否是该玩家。
    for _,p in ipairs(pls) do
      if p.phase == Player.Play then
        pp = p
      end
    end
    if #selected < pp:getMark("@v_xianwei_count-phase") +1 and (not VslUtil.is_jilei(pp, Fk:getCardById(to_select))) then
      return true
    end
    return false
  end,
  view_as = function(self, cards)
    local room = Fk:currentRoom()
    local pls = room.players
    local pp = nil
    --通过是否处于出牌阶段确认是否是该玩家。
    for _,p in ipairs(pls) do
      if p.phase == Player.Play then
        pp = p
      end
    end
    if #cards ~= ( pp:getMark("@v_xianwei_count-phase") +1 ) then
      return nil
    end
    local c = Fk:cloneCard("ex_nihilo")
    for _,cd in ipairs(cards) do
			c:addSubcard(cd)
		end
    c.skillName = self.name
    return c
  end,
  enabled_at_play = function(self, player)
    return player:isWounded()
  end,
}
local v_xianwei_count = fk.CreateTriggerSkill{
  name = "#v_xianwei_count",
  anim_type = "drawcard",

  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) then
      if data.card.skillName == "v_xianwei" then
      -- if table.contains(data.card.skillNames, "v_xianwei") then
        return true
      end
    end 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@v_xianwei_count-phase", 1)
  end,
}
v_xianwei:addRelatedSkill(v_xianwei_count)

--------------------------------------------------
--星猫
--------------------------------------------------

local v_xingmao_prohibit = fk.CreateProhibitSkill{
  name = "#v_xingmao_prohibit",
  is_prohibited = function(self, from, to, card)
    return false
  end,
  prohibit_use = function(self, player, card)
    return player:getMark("@@v_xingmao_prohibit_slash-turn") > 0 
      and card.type == Card.TypeBasic
  end,
}
local v_xingmao = fk.CreateTriggerSkill{
  name = "v_xingmao",
  anim_type = "defensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name)) then return false end
    local use = data
    if use.card.name == "jink" and use.toCard and use.toCard.trueName == "slash" then
      local effect = use.responseToEvent
      return effect.to == player.id
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local effect = data.responseToEvent
    local slasher = room:getPlayerById(effect.from)
    room:setPlayerMark(slasher, "@@v_xingmao_prohibit_slash-turn", 1)
  end,
}

v_xingmao:addRelatedSkill(v_xingmao_prohibit)

--------------------------------------------------
--星之谷米娅
--------------------------------------------------

local xingzhigumiya_mengmao = General(extension, "xingzhigumiya_mengmao", "psp", 2, 3, General.Female)
xingzhigumiya_mengmao:addSkill(v_baosha)
xingzhigumiya_mengmao:addSkill(v_xianwei)
xingzhigumiya_mengmao:addSkill(v_xingmao)

Fk:loadTranslationTable{
	["xingzhigumiya_mengmao"] = "星之谷米娅",
	["&xingzhigumiya_mengmao"] = "星之谷米娅",
	["#xingzhigumiya_mengmao"] = "星国萌猫",
	["$xingzhigumiya_mengmao"] = "简单",
	["designer:xingzhigumiya_mengmao"] = "NSX",
	["cv:xingzhigumiya_mengmao"] = "",
	["illustrator:xingzhigumiya_mengmao"] = "",
	["~xingzhigumiya_mengmao"] = "",
	["v_baosha"] = "薄纱",
	["#v_baosha_prohibit"] = "薄纱",
	--[":v_baosha"] = "锁定技，你的第一个回合开始前，你不是所有角色使用牌的合法目标。",
	[":v_baosha"] = "锁定技，你不是所有角色使用牌的合法目标。回合开始时，你失去此技能。",
	["$v_baosha"] = "",
	["v_xianwei"] = "衔尾",
	--["#v_xianwei_buff"] = "衔尾",
	[":v_xianwei"] = "出牌阶段，若你已受伤，你可以将X＋1张牌当【无中生有】使用。（X为本阶段内你以此法使用【无中生有】的次数）",
	["$v_xianwei"] = "",
	["@v_xianwei_count-phase"] = "衔尾",
	["v_xingmao"] = "星猫",
	["@@v_xingmao_prohibit_slash-turn"] = "星猫基本牌",
	[":v_xingmao"] = "锁定技，你使用【闪】响应【杀】后，此【杀】的使用者本回合不能使用基本牌。",
	["$v_xingmao"] = "",
	["#v_xingmao_log"] = "由于“%arg”的效果，%to 本回合不能使用 基本牌",
}

--------------------------------------------------
--咏星
--------------------------------------------------

local v_yongxing = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_yongxing",
  --(非必要）赋予摸牌型技能定义
  anim_type = "drawcard",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：造成伤害后
  events = {fk.Damage},
  --触发条件：
  --存在触发时机的角色、触发时机的角色为遍历到的角色、遍历到的角色具有本技能、造成伤害的角色为遍历到的角色。
  can_trigger = function(self, event, target, player, data)
    local damage = data
    return target and target == player and player:hasSkill(self.name) and
      damage.from == player
  end,
  on_trigger = function(self, event, target, player, data)
    for i = 1, data.damage do
      self:doCost(event, target, player, data)
    end
  end,
  -- on_cost = function(self, event, target, player, data)
  --   for i = 1, data.damage do
  --     return true
  --   end
  -- end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}

--------------------------------------------------
--扬歌
--------------------------------------------------

local v_yangge = fk.CreateTriggerSkill{
  name = "v_yangge",
  --赋予支援型技能定义
  anim_type = "support",
  --时机：阶段开始时
  events = {fk.EventPhaseStart},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能，遍历到的角色处于结束阶段，出牌阶段未被跳过，
  --         本回合未造成伤害、技能未失效（见on_trigger）。
  can_trigger = function(self, event, target, player, data)
    --阶段变化时，实现“是否跳出牌”的效果。
    --exist_or_not：用来确认是否跳过对应阶段，类似于以前的Player:isSkipped()
    return target == player and player:hasSkill(self.name) 
    and player.phase == Player.Finish and VslUtil.exist_or_not(player, Player.Play) 
    and player:getMark("#turn_damage-turn") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#v_yangge_ask"
    local peach_or_not = room:askForCard(player, 1, 1, false, self.name, true, ".", prompt)[1]
    --print(peach_or_not)
    if peach_or_not then
      room:throwCard(peach_or_not, self.name, player)
      local god_salvation = Fk:cloneCard("god_salvation")
      local new_use = {} ---@type CardUseStruct
      new_use.from = player.id
      new_use.tos = {}
      new_use.card = god_salvation
      new_use.skillName = self.name
      for _,p in ipairs(room:getAlivePlayers()) do
        if not player:isProhibited(p, new_use.card) then
      	  table.insert(new_use.tos, { p.id })
        end
      end
      if not VslUtil.is_jilei(player, new_use.card) then
      	room:useCard(new_use)
      end
    else
      player:turnOver()
      local savage_assault = Fk:cloneCard("savage_assault")
      local new_use = {} ---@type CardUseStruct
      new_use.from = player.id
      new_use.tos = {}
      new_use.card = savage_assault
      new_use.skillName = self.name
      for _,p in ipairs(room:getOtherPlayers(player)) do
        if not player:isProhibited(p, new_use.card) then
      	  table.insert(new_use.tos, { p.id })
        end
      end
      if not VslUtil.is_jilei(player, new_use.card) then
      	room:useCard(new_use)
      end
    end
  end,
}

--------------------------------------------------
--东爱璃
--角色马克：
--------------------------------------------------

local dongaili_xingtu = General(extension, "dongaili_xingtu", "psp", 3, 3, General.Female)
dongaili_xingtu:addSkill(v_yongxing)
dongaili_xingtu:addSkill(v_yangge)

Fk:loadTranslationTable{
	["dongaili_xingtu"] = "东爱璃",
	["&dongaili_xingtu"] = "东爱璃",
	["#dongaili_xingtu"] = "初入星途",
	["designer:dongaili_xingtu"] = "空月之羽",
	["cv:dongaili_xingtu"] = "",
	["illustrator:dongaili_xingtu"] = "Bison仓鼠",
	["~dongaili_xingtu"] = "",
	["v_yongxing"] = "咏星",
	[":v_yongxing"] = "锁定技，你造成1点伤害后，摸一张牌。",
	["$v_yongxing"] = "",
	["v_yangge"] = "扬歌",
	["#v_yangge_damage_checker"] = "扬歌",
	[":v_yangge"] = "结束阶段，若你未于本回合内造成过伤害，你可以<font color='#A9A9A9'>发动此技能</font>选择一项：1.翻面，视为使用一张【南蛮入侵】；2.弃置一张手牌，视为使用一张【桃园结义】。",
	["#v_yangge_ask"] = "请弃置一张手牌，视为使用 桃园结义<br/>否则你翻面，视为使用 南蛮入侵<br/><br/>操作提示：<br/>①桃园结义：选择一张手牌→确定；<br/>②南蛮入侵：取消。",
}

--------------------------------------------------
--袭穴
--技能马克：失去技能后对标记的处理可以在一键删除姬里面处理。
--------------------------------------------------
local v_xixue = fk.CreateTriggerSkill{
  name = "v_xixue",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
  -- --时机：手牌结算后
  -- events = {fk.CardUseFinished},
  --时机：宣告手牌使用时
  events = {fk.AfterCardUseDeclared},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能、遍历到的角色处于出牌阶段、满足技能条件
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and
      player.phase == Player.Play and self.can_xixue
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,

  --refresh_events = {fk.CardUseFinished, fk.EventPhaseStart},
  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    self.can_xixue = VslUtil.suit_close(data.card.suit) == player:getMark("#v_xixue_mark-phase")
    room:setPlayerMark(player, "#v_xixue_mark-phase", data.card.suit)
    room:setPlayerMark(player, "@v_xixue_mark-phase", data.card:getSuitString())
  end,
}

--------------------------------------------------
--小千村鼬鼬
--角色马克：袭穴
--------------------------------------------------

local xiaoqiancunyouyou_yaolingbaiyou = General(extension,"xiaoqiancunyouyou_yaolingbaiyou", "novus", 3, 3, General.Female)
xiaoqiancunyouyou_yaolingbaiyou:addSkill(v_xixue)

Fk:loadTranslationTable{
	["xiaoqiancunyouyou_yaolingbaiyou"] = "小千村鼬鼬",
	["&xiaoqiancunyouyou_yaolingbaiyou"] = "小千村柚柚",
	["#xiaoqiancunyouyou_yaolingbaiyou"] = "妖灵白鼬",
	["$xiaoqiancunyouyou_yaolingbaiyou"] = "简单",
	["designer:xiaoqiancunyouyou_yaolingbaiyou"] = "NSX",
	["cv:xiaoqiancunyouyou_yaolingbaiyou"] = "",
	["illustrator:xiaoqiancunyouyou_yaolingbaiyou"] = "",
	["~xiaoqiancunyouyou_yaolingbaiyou"] = "",
	["v_xixue"] = "袭穴",
	[":v_xixue"] = "你于出牌阶段内使用牌时，若此牌与你使用的上一张牌花色不同且颜色相同，你可以摸一张牌。",
	["$v_xixue"] = "",
	["@v_xixue"] = "袭穴",
	["@v_xixue_mark-phase"] = "袭穴",
}

--------------------------------------------------
--化武
--------------------------------------------------

local v_huawu = fk.CreateTriggerSkill{
  name = "v_huawu",
  anim_type = "support",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  --使用条件：（已完成）
  --通用：
  -- 触发时机的角色为遍历到的角色、遍历到的角色具有本技能。
  -- 遍历到的角色处于出牌阶段。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
      and player.phase == Player.Play
  end,
  --使用询问：（已完成）
  --阶段开始时：
  -- 如技能未被元初类技能失效，询问是否发动技能。
  --阶段结束时：
  -- return true
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      if room:askForSkillInvoke(player, self.name, data) then
        return true
      end
    else
      return true
    end
  end,
  --使用流程：（未完成）
  --阶段开始时：
  -- 检索牌堆。
  -- 如果是装备牌且玩家可以使用这张牌（可以使用prohibituse检查），检查牌对应的装备区，如可用，纳入表中。
  -- 如装备表非空，从中提取最多三件装备。（提取后需要从原表删除装备）
  -- 如果提取表非空，生成AG选择装备，然后使用对应的装备并生成mark（暂定phase后清洗）
  --阶段结束时：
  -- 根据角色mark对应的ID数字，检查装备区的牌，如果存在相同ID的牌，则将其返回牌堆。
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local room = player.room
      --记录牌堆的装备牌。
      local equips = {}
      --这里没摸到牌堆/弃牌堆的牌
      local draw = room.draw_pile
      for _,p in ipairs(draw) do
        local card = Fk:getCardById(p)
        --（后续可以补充isavailable判定确保这个装备是可以被玩家装备的，如果出现玩家因为无法使用或装备区封印穿不上去的情况可以噶了。)
        if card.type == Card.TypeEquip and (not player:prohibitUse(card)) then
          table.insert(equips, p)
        end
      end
      if #equips > 0 then
        local ag_equip = {}
        for i = 1, math.min(#equips, 3), 1 do
          local random_one = table.random(equips)
          table.insert(ag_equip, random_one)
          table.removeOne(equips, random_one)
        end
        if #ag_equip > 0 then
          room:fillAG(player, ag_equip)
          local id = room:askForAG(player, ag_equip, false, self.name)
          room:closeAG(player)
          local card = Fk:getCardById(id)
          if card then
            local new_use = {} ---@type CardUseStruct
            new_use.from = player.id
            --技能马克：可能会存在类似于知更酱多目标BUG的问题
            new_use.tos = {{ player.id }}
            new_use.card = card
            new_use.skillName = self.name
            --测试skillName是否有效
            --print(new_use.skillName)
            room:useCard(new_use)
            room:setPlayerMark(player, self.name, id)
          end
        end
      end
    -- 根据角色mark对应的ID数字，检查装备区的牌，如果存在相同ID的牌，则将其返回牌堆。
    else
      local mar = player:getMark(self.name)
      local equ = player:getCardIds(Player.Equip)
      if #equ > 0 then
        for _,cid in ipairs(equ) do
          if cid == mar then
            VslUtil.return_draw_pile(player, {mar}, self.name)
            -- local ram = math.random(1, #room.draw_pile + 1)
            -- room:moveCards({
            --   ids = {mar},
            --   from = player.id,
            --   toArea = Card.DrawPile,
            --   moveReason = fk.ReasonJustMove,
            --   skillName = self.name,
            --   drawPilePosition = ram,
            -- })
          end
        end
      end
      room:setPlayerMark(player, self.name, 0)
    end
  end,
}

--------------------------------------------------
--三叹
--TODO:如果选择用全局标记，需要确认这个技能会不会在三叹触发锦囊牌的时候
--       被无懈可击干扰技能发动（变成无懈可击触发三叹就搞笑了）
--FIXME:草 这个时机是失败的，根本没问无懈！！！！
--------------------------------------------------

--这是旧版（强力版），先凑活着用吧兄弟们。
local v_santan = fk.CreateTriggerSkill{
  name = "v_santan",
  --赋予输出型技能定义,
  anim_type = "offensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：卡牌生效前/目标指定后（看注释掉哪个就行）
  --注释：被无懈后依然能进入“卡牌生效前”流程
  --注释2：如想要实现未削弱版效果，只能通过“卡牌生效前”时机
  --注释3：“目标指定后”对无懈可击/闪这种不指定目标的牌无效，虽然可以变相实现现版本效果，但没必要（从log上来看不算完美实现）。
  events = {fk.PreCardEffect},
  -- events = {fk.TargetSpecified},
  --使用条件：
  --             触发时机的角色为遍历到的角色，遍历到的角色拥有此技能，
  --             遍历到的角色的某个标记符合要求，
  --             本次流程中第一次触发这个时机
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) 
    and player:getMark("@v_santan_mark") == "O"
    -- and data.firstTarget
  end,
  --使用流程：
  --令这张牌不可被响应。
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sendLog{
      type = "#v_santan_triggered",
      from = player.id,
      arg = self.name,
      card = { data.card.id },
    }
    data.disresponsive = true
  end,

  --本刷新仅用于在牌使用完毕后根据牌使用次数刷新BUFF
  --时机：手牌使用声明后
  refresh_events = {fk.AfterCardUseDeclared},
  --刷新条件：
  --             触发时机的角色为遍历到的角色，遍历到的角色拥有此技能，
  --             遍历到的角色的某个标记符合要求，
  --             本次流程中第一次触发这个时机（先删了）
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
  end,
  --刷新方式：待定
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local v_stm = (player:getMark("card_used") + 1) % 3
    room:setPlayerMark(player, "@v_santan_mark", v_stm)
    if v_stm == 0 then
      room:setPlayerMark(player, "@v_santan_mark", "O")
    end
  end
}

-- 这也没用，规避无懈无效不说，on_use注释部分还有个莫名其妙的nil，先做个旧版的吧。
-- local v_santan = fk.CreateTriggerSkill{
--   name = "v_santan",
--   --赋予输出型技能定义,
--   anim_type = "offensive",
--   --技能为锁定技，满足条件后强制发动
--   frequency = Skill.Compulsory,
--   --时机：卡牌生效前
--   --注释：被无懈后依然能进入“卡牌生效前”流程
--   -- events = {fk.PreCardEffect},
--   events = {fk.TargetSpecified},
--   --使用条件：
--   --             触发时机的角色为遍历到的角色，遍历到的角色拥有此技能，
--   --             遍历到的角色的某个标记符合要求，
--   --             本次流程中第一次触发这个时机
--   can_trigger = function(self, event, target, player, data)
--     return target == player and player:hasSkill(self.name) 
--     and player:getMark("@v_santan_mark") == "O"
--     -- 下面这行本来是想用来规避无懈的，结果好像没什么用.zip
--     and not (Fk.currentResponsePattern and Fk.currentResponsePattern == "nullification")
--     -- and player:getMark("card_used") % 3 == 2
--     and data.firstTarget
--   end,
--   --使用流程：
--   --令这张牌不可被响应。
--   on_use = function(self, event, target, player, data)
--     local room = player.room
--     room:sendLog{
--       type = "#v_santan_triggered",
--       from = player.id,
--       arg = self.name,
--       card = { data.card.id },
--     }
--     local tar = AimGroup:getAllTargets(data.tos)
--     if #tar > 0 then
--       for _, p in ipairs(tar) do
--         -- local pls = room:getPlayerById(p)

--         data.disresponsiveList = data.disresponsiveList or {}
--         if #data.disresponsiveList == 0 then
--           table.insert(data.disresponsiveList, p)
--         end
--         --因为这部分内容的存在，导致了attempt to get length of a nil value(local 'self')
--         --util.lua:88 table.contains
--         --room.lua:1995 doCardUseEffect
--         --usecard.lua:197···
--         table.insertIfNeed(data.disresponsiveList, p)
--       end
--     end
--     -- data.disresponsive = true
--   end,

--   --本刷新仅用于在牌使用完毕后根据牌使用次数刷新BUFF
--   --时机：手牌使用声明后
--   refresh_events = {fk.AfterCardUseDeclared},
--   --刷新条件：
--   --             触发时机的角色为遍历到的角色，遍历到的角色拥有此技能，
--   --             遍历到的角色的某个标记符合要求，
--   --             本次流程中第一次触发这个时机（先删了）
--   can_refresh = function(self, event, target, player, data)
--     return target == player and player:hasSkill(self.name)
--     -- return data.firstTarget
--   end,
--   --刷新方式：待定
--   on_refresh = function(self, event, target, player, data)
--     local room = player.room
--     local v_stm = (player:getMark("card_used") + 1) % 3
--     room:setPlayerMark(player, "@v_santan_mark", v_stm)
--     if v_stm == 0 then
--       room:setPlayerMark(player, "@v_santan_mark", "O")
--     end
--   end
-- }

--------------------------------------------------
--希贝尔
--------------------------------------------------

local xibeier_sanjueweibian = General(extension, "xibeier_sanjueweibian", "facemoe", 4, 4, General.Female)
xibeier_sanjueweibian:addSkill(v_huawu)
xibeier_sanjueweibian:addSkill(v_santan)

Fk:loadTranslationTable{
	["xibeier_sanjueweibian"] = "希贝尔",
	["&xibeier_sanjueweibian"] = "希贝尔",
	["#xibeier_sanjueweibian"] = "「三绝韦编」",
	["designer:xibeier_sanjueweibian"] = "空月之羽",
	["cv:xibeier_sanjueweibian"] = "",
	["illustrator:xibeier_sanjueweibian"] = "",
	["~xibeier_sanjueweibian"] = "",
	["v_huawu"] = "化武",
	[":v_huawu"] = "出牌阶段开始时，你可以<font color='#A9A9A9'>发动此技能</font>，从牌堆中的随机3张装备牌中使用一张，出牌阶段结束时，将你装备区内的此牌返回牌堆。",
	["$v_huawu"] = "",
	["^AG_v_huawu"] = "<b>化武</b><br/>双击以选择一张装备牌使用之",
	["v_santan"] = "三叹",
	["@v_santan_mark"] = "三叹蓄力中",
	-- [":v_santan"] = "锁定技，你使用的第3X张牌不能被【无懈可击】以外的牌抵消。",
	[":v_santan"] = "锁定技，你使用的第3X张牌不可被响应。",
	["$v_santan"] = "",
	-- ["#v_santan_triggered"] = "%from 的“%arg”的被触发，%from 使用的 %card 不能被 <b><font color='yellow'>无懈可击</font></b> 以外的牌抵消",
	["#v_santan_triggered"] = "%from 的“%arg”的被触发，%from 使用的 %card 不可被响应。",
}

--------------------------------------------------
--低吟
--------------------------------------------------

local v_diyin = fk.CreateViewAsSkill{
  name = "v_diyin",
  interaction = UI.ComboBox {choices = VslUtil.damage_tricks},
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function()
    return false
  end,
  view_as = function(self, cards)
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(Self:getCardIds(Player.Hand))
    card.skillName = self.name
    return card
  end,
}
local v_diyin_draw = fk.CreateTriggerSkill{
  name = "#v_diyin_draw",
  --赋予输出型技能定义
  anim_type = "offensive",
  --时机：手牌结算后
  events = {fk.CardUseFinished},
  --触发条件：
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
    and data.card and data.card.skillName == "v_diyin"
    -- and data.card and table.contains(data.card.skillNames, "v_diyin")
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pla = room:getPlayerById(data.from)
    if pla and pla:isAlive() then
      room:drawCards(pla, 1, "v_diyin")
    end
    for _, p in ipairs(room:getAllPlayers()) do
      if p:getMark("v_diyin_damage-phase") > 0 then
        room:setPlayerMark(p, "v_diyin_damage-phase", 0)
        --之后能否被技能指定为目标可以在这判定
        room:drawCards(p, 1, "v_diyin")
      end
    end
  end,

  --刷新时机：受到伤害后
  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    return data.card and data.card.skillName == "v_diyin" 
    -- return data.card and table.contains(data.card.skillNames, "v_diyin")
    and data.to and data.to:isAlive()
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(data.to, "v_diyin_damage-phase", 1)
  end
}
v_diyin:addRelatedSkill(v_diyin_draw)


--------------------------------------------------
--库姬
--角色马克：
--------------------------------------------------

local kuji_chaoyongyuge = General(extension, "kuji_chaoyongyuge", "facemoe", 4, 4, General.Female)
kuji_chaoyongyuge:addSkill(v_diyin)

Fk:loadTranslationTable{
	["kuji_chaoyongyuge"] = "库姬",
	["&kuji_chaoyongyuge"] = "库姬",
	["#kuji_chaoyongyuge"] = "潮涌余歌",
	["$kuji_chaoyongyuge"] = "进阶",
	["designer:kuji_chaoyongyuge"] = "月音风源",
	["cv:kuji_chaoyongyuge"] = "",
	["illustrator:kuji_chaoyongyuge"] = "",
	["~kuji_chaoyongyuge"] = "",
	["v_diyin"] = "低吟",
	["#v_diyin_draw"] = "低吟",
	[":v_diyin"] = "出牌阶段限一次，你可以将所有手牌当一张伤害类锦囊牌使用。此牌结算结束后，你与因此牌受到伤害的角色各摸一张牌。",
	["$v_diyin1"] = "",
	["$v_diyin2"] = "",
	["@v_diyin_useCard"] = "请将所有手牌当 %src 使用",
	["~v_diyin"] = "选择目标→点击“确定”",
	["#v_diyin_error"] = "%from 不能通过“%arg”视为使用任何牌",
}

--------------------------------------------------
--矛盾
--技能马克：
--------------------------------------------------

local v_maodun = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_maodun",
  --(非必要）赋予进攻型技能定义
  anim_type = "offensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：受到伤害时，造成伤害时
  events = {fk.DamageInflicted,fk.DamageCaused},
  --触发条件：
  --触发时机的角色为遍历到的角色、遍历到的角色具有本技能、造成的伤害大于0；
  --遍历到的角色体力值为全场唯一最高。
  --（后续补充）非光伤
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name) and
      data.damage > 0) then 
      return false 
    end
    local room = player.room
    local others = room:getOtherPlayers(player)
    for _,p in ipairs(others) do
      if p.hp >= player.hp then
        return false
      end
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}

--------------------------------------------------
--制冷
--获取寒冰剑部分原Vup杀流程：
--奇数回合准备阶段，将一张寒冰剑放置于除外牌堆里，进行选择：
--如不用，置于某个未知牌堆
--如用，直接使用（参考成长）

--TODO:装备区是否封印的检测；
--  为优化体验避免没剑还询问技能，把检测放到了can_trigger；如对游戏体验变化太大可修改回on_cost。
--------------------------------------------------

local v_zhileng = fk.CreateTriggerSkill{
  name = "v_zhileng",
  anim_type = "defensive",
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  --触发条件：（已完成）
  --通用：
  -- 触发时机的角色为遍历到的角色、遍历到的角色具有本技能。
  --阶段开始时：【可以考虑在这里做个装备区是否有寒冰剑的判定】
  -- 游戏轮数为奇数；遍历到的角色处于准备阶段。
  -- （武器存在且为寒冰剑）这项不为真
  --受到伤害时：
  -- 伤害大于0，遍历到的角色牌区牌>=2
  -- （待补充）非光伤
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if target ~= player or not player:hasSkill(self.name) then return false end
    if event == fk.EventPhaseStart then
      local weapon1 = player:getEquipment(Card.SubtypeWeapon) 
      return room:getTag("RoundCount") % 2 == 1 and player.phase == Player.Start
        and not (weapon1 and Fk:getCardById(weapon1).name == "ice_sword")
    else
      return data.damage > 0 and #player:getCardIds{Player.Hand, Player.Equip} >= 2
    end
  end,
  --使用询问：
  --阶段开始时：
  -- 在牌堆和弃牌堆找寒冰剑。（寻找判定中需要注意后续补充装备区是否被废除或无法使用）
  -- 如找到，放置于除外区，并确认玩家可以使用这张牌（可以通过prohibituse来）后询问技能是否发动
  --受到伤害时：
  -- askfordiscard即可，2牌，带装备玩。
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否使用寒冰剑，否则就把寒冰剑返回牌堆。
    if event == fk.EventPhaseStart then
      --记录牌堆及弃牌堆的寒冰剑。
      local equips = {}
      --这里没摸到牌堆/弃牌堆的牌
      local draw = room.draw_pile
      local discard = room.discard_pile
      for _,p in ipairs(draw) do
        local card = Fk:getCardById(p)
        --（后续可以补充isavailable判定确保这个装备是可以被玩家装备的，如果出现玩家因为装备区废除穿不上去的情况可以噶了。)
        if card and card.name == "ice_sword" then
          table.insert(equips, p)
        end
      end
      for _,p in ipairs(discard) do
        local card = Fk:getCardById(p)
        --（后续可以补充isavailable判定确保这个装备是可以被玩家装备的，如果出现玩家因为装备区废除穿不上去的情况可以噶了。)
        if card and card.name == "ice_sword" then
          table.insert(equips, p)
        end
      end
      if #(equips) > 0 then
        local x = #(equips)
        local c = math.random(1, x)
        local carcar = equips[c]
        local carcarcar = Fk:getCardById(carcar)
        local prompt = "v_zhileng_ask2:::"..carcarcar.name
        player:addToPile(self.name, carcarcar, true, self.name)
        if (not player:prohibitUse(carcarcar)) then
          local car = room:askForSkillInvoke(player, self.name, data, prompt)
          if car then
            self.cost_data = carcar
            return true
          else
            VslUtil.return_draw_pile(player, {carcar}, self.name)
            -- local ram = math.random(1, #room.draw_pile + 1)
            -- room:moveCards({
            --   ids = {carcar},
            --   from = player.id,
            --   toArea = Card.DrawPile,
            --   moveReason = fk.ReasonJustMove,
            --   skillName = self.name,
            --   drawPilePosition = ram,
            -- })
          end
        end
      end
    --选择弃牌与否
    else
      local prompt = "v_zhileng_ask1"
      local disc = room:askForDiscard(player, 2, 2, true, self.name, true, ".", prompt)
      return #disc == 2
    end
  end,
  --使用流程：
  --阶段开始时：
  -- 如确定使用，直接用；如不用，返回牌堆。
  --受到伤害时：
  --setemotion后，return true
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local is = self.cost_data
      local icesword = Fk:getCardById(is)
      local new_use = {} ---@type CardUseStruct
      new_use.from = player.id
      --技能马克：可能会存在类似于知更酱多目标BUG的问题
      new_use.tos = {{ player.id }}
      new_use.card = icesword
      new_use.skillName = self.name
      --测试skillName是否有效
      --print(new_use.skillName)
      room:useCard(new_use)
    else
      room:setEmotion(player, "./packages/vupslash/image/anim/jiuma_small")
      return true
    end
  end,
}

--------------------------------------------------
--玖麻
--------------------------------------------------

local jiuma_hanshixianggong = General(extension, "jiuma_hanshixianggong", "facemoe", 4, 5, General.Female)
jiuma_hanshixianggong:addSkill(v_maodun)
jiuma_hanshixianggong:addSkill(v_zhileng)

Fk:loadTranslationTable{
	["jiuma_hanshixianggong"] = "玖麻",
	["&jiuma_hanshixianggong"] = "玖麻",
	["#jiuma_hanshixianggong"] = "函矢相攻",
	["designer:jiuma_hanshixianggong"] = "月音风源、NSX",
	["cv:jiuma_hanshixianggong"] = "",
	["illustrator:jiuma_hanshixianggong"] = "",
	["~jiuma_hanshixianggong"] = "",
	["v_maodun"] = "矛盾",
	[":v_maodun"] = "锁定技，你造成或受到伤害时，若你的体力值为全场唯一最高，此伤害＋1。",
	["$v_maodun"] = "啊~玖麻的力量（迫真）",
	["v_zhileng"] = "制冷",
	[":v_zhileng"] = "准备阶段，若游戏轮数为奇数，你可以从牌堆、弃牌堆使用一张【寒冰剑】。<br/>你受到伤害时，你可以弃置两张牌，防止之。",
	["$v_zhileng"] = "",
	["v_zhileng_ask1"] = "你可以弃置两张牌，防止此伤害",
	["v_zhileng_ask2"] = "你可以使用牌堆、弃牌堆中的一张 %arg",
	["~v_zhileng"] = "使用：选择目标（若需要）→确定<br/>不使用：取消",
}

--------------------------------------------------
--龙息
--------------------------------------------------

local v_longxi = fk.CreateTriggerSkill{
  name = "v_longxi",
  --赋予输出型技能定义,
  anim_type = "offensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  --触发条件：触发时机的角色为遍历到的角色，触发者拥有此技能，
  --             触发者本回合已使用过一张牌，触发者处于出牌阶段，
  --             本次流程中第一次触发这个时机
  can_trigger = function(self, event, target, player, data)
    local targets = data
    return target == player and player:hasSkill(self.name) 
    and player.phase == Player.Play and player:getMark("#v_longxi_mark-turn") == 2
    and targets.firstTarget
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = data
    local longxi_tar = AimGroup:getAllTargets(targets.tos)
    --选择这张牌指定的所有目标，执行拆一张牌的指令
    for _, p in ipairs(longxi_tar) do
      local pls = room:getPlayerById(p)
      --如果被选定的目标两个区域都没牌则不执行下一步。
      if (not pls:isNude()) then
        --由遍历到的角色对目标选择手牌区/装备区的一张牌
        local cid = room:askForCardChosen(
          player,
          pls,
          "he",
          self.name
        )
        --将这张牌丢弃牌区
        room:throwCard(cid, self.name, pls, player)
      end
    end
  end,
  refresh_events = {fk.TargetSpecified},
  can_refresh = function(self, event, target, player, data)
    local targets = data
    if not (target == player and player:hasSkill(self.name)) then
      return false
    end
    return player.phase == Player.Play and targets.firstTarget
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player,"#v_longxi_mark-turn",1)
  end
}

--------------------------------------------------
--卡诺娅
--角色马克：
--------------------------------------------------

local kanuoya_akanluerbanlong = General(extension, "kanuoya_akanluerbanlong", "xuyanshe", 4, 4, General.Female)
kanuoya_akanluerbanlong:addSkill(v_longxi)

Fk:loadTranslationTable{
	["kanuoya_akanluerbanlong"] = "卡诺娅",
	["&kanuoya_akanluerbanlong"] = "卡诺娅",
	["#kanuoya_akanluerbanlong"] = "阿坎鲁尔半龙",
	["$kanuoya_akanluerbanlong"] = "萌新",
	["designer:kanuoya_akanluerbanlong"] = "月音风源",
	["cv:kanuoya_akanluerbanlong"] = "",
	["illustrator:kanuoya_akanluerbanlong"] = "",
	["~kanuoya_akanluerbanlong"] = "",
	["v_longxi"] = "龙息",
	["v_longxi_getmark"] = "龙息",
	[":v_longxi"] = "锁定技，你于出牌阶段内使用的第二张牌指定目标后，你破坏所有目标角色的各一张牌。",
	["$v_longxi"] = "",
}

--------------------------------------------------
--联袂
--技能马克：
--------------------------------------------------

local v_lianmei = fk.CreateTriggerSkill{
  name = "v_lianmei",
  --赋予控场型技能定义
  anim_type = "control",
  --时机：受到伤害后
  events = {fk.Damaged},
  --触发条件：
  -- 触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  -- 伤害大于0，存在伤害源
  can_trigger = function(self, event, target, player, data)
    local damage = data
    return target == player and player:hasSkill(self.name) 
    and damage.damage > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#v_lianmei_ask"
    local alive = room:getAlivePlayers()
    local targets = {}
    for _,p in ipairs(alive) do
      -- TODO：这里后续可以补充“可被技能指定”与“你的技能可以对其生效”判定，待定
      if (not p:isNude()) then
        table.insert(targets, p.id)
      end
    end
    local ret = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
    if #ret > 0 then
      self.cost_data = ret[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    if not tar:isNude() then
      room:askForDiscard(tar, 1, 1, true, self.name, false)
    end
    --这里可以补一个玩家能否弃置对方一张牌
    local card = room:askForCardChosen(player, tar, "he", self.name)
    room:throwCard(card, self.name, tar, player)
  end,
}

--------------------------------------------------
--小希小桃
--角色马克：
--------------------------------------------------

local xiaoxixiaotao_eniac = General(extension, "xiaoxixiaotao_eniac", "xuyanshe", 4, 4, General.Female)
xiaoxixiaotao_eniac:addSkill(v_lianmei)

Fk:loadTranslationTable{
	["xiaoxixiaotao_eniac"] = "小希小桃",
	["&xiaoxixiaotao_eniac"] = "小希小桃",
	["#xiaoxixiaotao_eniac"] = "ENIAC",
	["$xiaoxixiaotao_eniac"] = "萌新",
	["designer:xiaoxixiaotao_eniac"] = "NSX、yakui",
	["cv:xiaoxixiaotao_eniac"] = "",
	["illustrator:xiaoxixiaotao_eniac"] = "",
	["~xiaoxixiaotao_eniac"] = "",
	["v_lianmei"] = "联袂",
	[":v_lianmei"] = "你受到伤害后，你可以指定一名角色，<font color='#A9A9A9'>发动此技能</font>，令其弃置一张牌，然后你破坏其一张牌。",
	["$v_lianmei1"] = "",
	["$v_lianmei2"] = "",
	["#v_lianmei_ask"] = "你可以发动“联袂”，令一名角色弃置一张牌再被你破坏其一张牌",
}

--------------------------------------------------
--狐尾扇
--技能马克：后续可以给展示用的牌做cardflag
--------------------------------------------------

local v_huweishan = fk.CreateTriggerSkill{
  name = "v_huweishan",
  --赋予输出型技能定义
  anim_type = "offensive",
  -- --时机：手牌结算后
  -- events = {fk.CardUseFinished},
  --时机：宣告手牌使用时
  events = {fk.AfterCardUseDeclared},
  --（阶段变化时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；存在实体卡（后续需要测试，如不成功可以通过ID>0处理）。
  --             使用的牌为杀；本回合只使用过一次技能。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card
    and data.card.trueName == "slash" and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card_id = room:drawCards(player, 1, self.name, top)[1]
    local card = Fk:getCardById(card_id)
    room:obtainCard(player, card_id, true, fk.ReasonDraw)
    room:delay(250)
    if room:getCardOwner(card_id) == player then
      player:showCards(card)
      if card.type == Card.TypeBasic then
        local prompt = "v_huweishan_throw_choice"
        if VslUtil.yes_or_no(player, self.name, prompt) then
          room:setEmotion(player, "./packages/vupslash/image/anim/xingmengzhenxue")
          room:throwCard(card_id, self.name, player, player)
          player:addCardUseHistory(data.card.trueName, -1)
          room:sendLog{
            type = "#v_huweishan_success",
            from = player.id,
            arg = self.name,
            card = { card_id },
          }
        end
      end
    end
  end,
}

--------------------------------------------------
--星梦真雪
--------------------------------------------------

local xingmengzhenxue_rongyixiaohu = General(extension,"xingmengzhenxue_rongyixiaohu", "niya", 4, 4, General.Bigender)
xingmengzhenxue_rongyixiaohu:addSkill(v_huweishan)

Fk:loadTranslationTable{
	["xingmengzhenxue_rongyixiaohu"] = "星梦真雪",
	["&xingmengzhenxue_rongyixiaohu"] = "星梦真雪",
	["#xingmengzhenxue_rongyixiaohu"] = "融熠宵狐",
	["$xingmengzhenxue_rongyixiaohu"] = "萌新",
	["designer:xingmengzhenxue_rongyixiaohu"] = "戦、月音风源",
	["cv:xingmengzhenxue_rongyixiaohu"] = "",
	["illustrator:xingmengzhenxue_rongyixiaohu"] = "",
	["~xingmengzhenxue_rongyixiaohu"] = "",
  	["v_huweishan"] = "狐尾扇",
	["v_huweishan_throw"] = "狐尾扇",
	[":v_huweishan"] = "每回合限一次，你使用【杀】时，你可以<font color='#A9A9A9'>发动此技能</font>，摸一张牌并展示之，若之为基本牌则你可以弃置之，令此【杀】不计入出牌阶段的使用次数。",
	--[":v_huweishan"] = "每回合限一次，你使用【杀】时，你可以，摸一张牌并展示之，若之为基本牌则你可以弃置之，令此【杀】不计入出牌阶段的使用次数。",
  	["$v_huweishan1"] = "",
	["$v_huweishan2"] = "",
	["#v_huweishan_success"] = "由于“%arg”的效果，%from 的 %card 不计入使用次数",
	["v_huweishan_throw_choice"] = "你可以弃置获得的牌，令此杀不计入使用次数",
}

--------------------------------------------------
--无忌
--技能马克：刷新标记暂时就不放在refresh_event了，我也不确定优先级（呆滞）
--------------------------------------------------

--写完才发现好像完全没必要再写个function（乐）
--虽然超大规模降低了可读性，但我懒得改了~
local function refresh_wuji_buding_mark(player, suit)
  local record_suits = player:getMark("v_wuji_record")
  local room = player.room
  local suit_s = {}
  --存在0个花色：直接为record_suit赋予suit变量。
  if record_suits == 0 then
    record_suits = suit
  --存在>=一个花色：提取现有花色增加目标花色后，
  --  将其按照suits表的顺序进行比较并 依次 放入表内。
  elseif type(record_suits) == "string" then
    suit_s = record_suits:split("+")
    table.insertIfNeed(suit_s, suit)
    local show_suit = {}
    for _,s in ipairs(VslUtil.suits) do
      if table.contains(suit_s, s) then
        table.insertIfNeed(show_suit, s)
      end
    end
    record_suits = table.concat(show_suit, "+")
  end
  --设置对应的标记。
  room:setPlayerMark(player, "v_wuji_record", record_suits)
	room:setPlayerMark(player, "@v_wuji_suit", table.concat(
    table.map(record_suits:split("+"), function(s) return VslUtil.card_suits_table[s] end)
    , ""))
  return #suit_s
end
local v_wuji = fk.CreateTriggerSkill{
  name = "v_wuji",
  --赋予特殊型技能定义
  anim_type = "special",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --启动后不默认播放技能触发
  mute = true,
  --时机：手牌结算后
  events = {fk.CardUseFinished},
  --触发条件：
  --触发时机的角色为遍历到的角色、遍历到的角色存在此技能；
  --存在花色且不为无色；
  --本花色未被记录过。
  can_trigger = function(self, event, target, player, data)
    local record_suits = player:getMark("v_wuji_record")
    local suit_s = {}
    local su_st = VslUtil.suit_string(data.card.suit)
    local record = false
    if type(record_suits) == "string" then
      suit_s = record_suits:split("+")
      for _,s in ipairs(suit_s) do
        if su_st == s then
          record = true
          break
        end
      end
    end
    return target == player and player:hasSkill(self.name) 
      and data.card.suit and data.card.suit ~= Card.NoSuit
      and (not record)
  end,
  on_use = function(self, event, target, player, data)
    --遍历全场所有角色，对持有此技能的角色询问其是否发动技能。
    local room = player.room
    local su_st = VslUtil.suit_string(data.card.suit)
    local count
    count = refresh_wuji_buding_mark(player, su_st)
    if count == 3 then
      room:notifySkillInvoked(player, self.name)
      room:broadcastSkillInvoke(self.name, -1)
      room:drawCards(player, 1, self.name)
    elseif count == 4 then
      room:notifySkillInvoked(player, self.name)
      room:broadcastSkillInvoke(self.name, -1)
      room:setPlayerMark(player, "v_wuji_record", 0)
      room:setPlayerMark(player, "@v_wuji_suit", 0)
      local alives = room:getAlivePlayers()
      local prompt = "v_wuji_ask"
      local targets = {}
      for _, p in ipairs(alives) do
        table.insert(targets, p.id)
      end
      if #targets > 0 then
        local tar = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)[1]
        if tar then
          local ta = room:getPlayerById(tar)
          if ta ~= player then
            --doindicate的两个参数一个为integer，一个为table
            room:doIndicate(player.id, { tar })
          end
          room:damage{
            from = player,
            to = ta,
            damage = 1,
            skillName = self.name,
          }
        end
      end
    end
  end,
}

--------------------------------------------------
--幼步玎
--------------------------------------------------

local buding_lichilingya = General(extension, "buding_lichilingya", "niya", 3, 3, General.Female)
buding_lichilingya:addSkill(v_wuji)

Fk:loadTranslationTable{
	["buding_lichilingya"] = "幼步玎",
	["&buding_lichilingya"] = "步玎",
	["#buding_lichilingya"] = "俐齿伶牙",
	["$buding_lichilingya"] = "简单",
	["designer:buding_lichilingya"] = "月音风源",
	["cv:buding_lichilingya"] = "",
	["illustrator:buding_lichilingya"] = "",
	["~buding_lichilingya"] = "",
	["v_wuji"] = "无忌",
	["v_wuji_record"] = "无忌",
	["@v_wuji_suit"] = "无忌蓄力中",
	[":v_wuji"] = "锁定技，你使用牌结算结束后，若此牌花色未记录，记录之，若你已记录：<br/><font color='#9400D3'>三种花色</font>，摸一张牌；<br/><font color='#9400D3'>四种花色</font>，清除记录，对一名角色造成1点伤害。",
	["$v_wuji"] = "",
	["v_wuji_ask"] = "请对一名角色造成1点伤害",
}

--------------------------------------------------
--浅唱
--------------------------------------------------

local v_qianchang = fk.CreateViewAsSkill{
  name = "v_qianchang",
  interaction = UI.ComboBox {choices = VslUtil.not_damage_tricks},
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function()
    return false
  end,
  view_as = function(self, cards)
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(Self:getCardIds(Player.Hand))
    card.skillName = self.name
    return card
  end,
}

--------------------------------------------------
--明贤
--TODO: 
--------------------------------------------------

local v_mingxian = fk.CreateTriggerSkill{
  name = "v_mingxian",
  --赋予防御型技能定义,
  anim_type = "defensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：目标确定后
  events = {fk.TargetSpecified},
  --触发条件：
  --         遍历到的角色具有本技能
  --         存在卡，且卡的真名为“杀”
  --         卡的颜色为红色/卡的名字为“雷杀”
  --         使用牌的角色存在、使用牌的角色存活、使用牌的角色不为遍历到的角色
  --         牌的目标存在，牌的目标中存在遍历到的角色
  --         本次流程中第一次触发这个时机
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local pla = room:getPlayerById(data.from)
    local target_contain_player = false
    for _, p in ipairs(AimGroup:getAllTargets(data.tos)) do
      if p == player.id then
        target_contain_player = true
      end
    end
    return player:hasSkill(self.name) 
    and data.card and data.card.trueName == "slash" 
    and (data.card.color == Card.Red or data.card.name == "thunder__slash")
    and pla and pla:isAlive() and pla ~= player
    and #AimGroup:getAllTargets(data.tos) > 0 and target_contain_player
    and data.firstTarget
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pla = room:getPlayerById(data.from)
    --if data.from ~= player then
    --doindicate的两个参数均为integer类型，一般为角色id
    room:doIndicate( pla.id, {player.id} )
    --end
    --询问是否交对应的牌，如存在，继续，否则失效。
    local prompt = "#v_mingxian_give:"..player.id
    local slash_or_not = room:askForCard(pla, 1, 1, false, self.name, true,"slash|.|.|hand" ,prompt)[1]
    if slash_or_not then
      room:obtainCard(player, slash_or_not, true, fk.ReasonGive)
    else
      room:setEmotion(player, "./packages/vupslash/image/anim/skill_nullify")
      table.insert(data.nullifiedTargets, player.id)
    end
  end,
}

--------------------------------------------------
--诗小雅
--角色马克：
--------------------------------------------------

local shixiaoya_xianyadan = General(extension,"shixiaoya_xianyadan", "chaociyuan", 3, 3, General.Female)
shixiaoya_xianyadan:addSkill(v_qianchang)
shixiaoya_xianyadan:addSkill(v_mingxian)

Fk:loadTranslationTable{
	["shixiaoya_xianyadan"] = "诗小雅",
	["&shixiaoya_xianyadan"] = "诗小雅",
	["#shixiaoya_xianyadan"] = "贤鸭蛋",
	["$shixiaoya_xianyadan"] = "进阶",
	["designer:shixiaoya_xianyadan"] = "NSX",
	["cv:shixiaoya_xianyadan"] = "",
	["illustrator:shixiaoya_xianyadan"] = "",
	["~shixiaoya_xianyadan"] = "",
	["v_qianchang"] = "浅唱",
	[":v_qianchang"] = "出牌阶段限一次，你可以将所有手牌当一张非伤害类普通锦囊牌使用。",
	["$v_qianchang1"] = "",
	["$v_qianchang2"] = "",
	["@v_qianchang_useCard"] = "请将所有手牌当 %src 使用",
	["~v_qianchang"] = "选择目标→点击“确定”",
	["#v_qianchang_error"] = "%from 不能通过“%arg”视为使用任何牌",
	["v_mingxian"] = "明贤",
	[":v_mingxian"] = "锁定技，你成为其他角色使用红色【杀】或雷【杀】的目标后，该角色须交给你一张【杀】，否则此牌对你无效。",
	["#v_mingxian_give"] = "请交给 %src 一张杀，否则此【杀】对其无效",
	["$v_mingxian"] = "",
}

--------------------------------------------------
--抹挑
--技能马克：
-- “本回合可以造成的伤害最高为1”后续可以补动画。
--注释：本技能将导致造成一点伤害后，伤害传导也无效。
--------------------------------------------------

local v_motiao = fk.CreateTriggerSkill{
  name = "v_motiao",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
  --时机：阶段开始时，目标指定后
  events = {fk.EventPhaseStart, fk.TargetSpecified},
  --触发条件：
  --（阶段开始时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              被遍历到的角色处于回合开始阶段。
  --（目标指定时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --             存在回合开始阶段时使用此技能的标签；
  --             被指定的角色中存在遍历到的角色。
  --             本次流程中第一次触发这个时机
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self.name)
      and player.phase == Player.Start
    elseif event == fk.TargetSpecified then
      local room = player.room
      --遍历所有被指定到的角色，确认是否存在遍历到的角色
      local motiao_useornot = false
      local targets = data
      local motiao_tar = AimGroup:getAllTargets(targets.tos)
      for _, p in ipairs(motiao_tar) do
        local pls = room:getPlayerById(p)
        if pls == player then
          motiao_useornot = true
        end
      end
      return target == player and player:hasSkill(self.name)
      and player:getMark("@@v_motiao_using-turn") > 0
      and motiao_useornot
      and targets.firstTarget
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否发动技能。
    if event == fk.EventPhaseStart then
      local prompt = "v_motiao_choice"
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        return true
      end
    --满足技能发动要求后，锁定发动。
    elseif event == fk.TargetSpecified and player:getMark("@@v_motiao_using-turn") > 0 then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --以on_cost中做出选择为代价，本回合内你只能造成1点伤害，你使用牌指定自己为目标之一后，摸一张牌。
    if event == fk.EventPhaseStart then
      room:setPlayerMark(player, "@@v_motiao_using-turn", 1)
    --摸一张牌
    elseif event == fk.TargetSpecified then
      player:drawCards(1, self.name)
    end
  end,

  --伤害在这里刷新。
  refresh_events = {fk.DamageCaused},
  -- 刷新时机：
  --             触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --             存在回合开始阶段时使用此技能的标签；
  --             造成的伤害大于0；
  --             非光属性伤害（暂未实装）。
  can_refresh = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name)) then
      return false
    end
    return player:getMark("@@v_motiao_using-turn") > 0
      and data.damage > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local x = math.min(data.damage, 1 - player:getMark("#turn_damage-turn"))
    if x < data.damage then
      if x > 0 then
        data.damage = 1
        --return false
      else
        room:setEmotion(data.to, "./packages/vupslash/image/anim/skill_nullify")
        room:sendLog{
          type = "#defense_damage",
          from = player.id,
          --log.to是数组
          to = {data.to.id},
          arg = self.name,
          arg2 = data.damage,
        }
        data.damage = 0
      end
    end
  end
}
-- v_motiao:addRelatedSkill(v_motiao_damage_checker)

--------------------------------------------------
--连奏
--技能马克：打出的牌可能会无法返回number；丈八在下版本前可能还是算点数的。
--------------------------------------------------

local v_lianzou = fk.CreateTriggerSkill{
  name = "v_lianzou",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
   --技能为限定技
  frequency = Skill.Limited,
  --时机：阶段结束时
  events = {fk.EventPhaseEnd},
  --触发条件：
  --（阶段结束时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              被遍历到的角色处于出牌阶段。
  --              被遍历到的角色本场游戏使用此技能的次数为0
  --              被遍历到的角色本轮使用/打出牌的点数之和>=50（打出是否算入在内待定）
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
    and player.phase == Player.Play
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and player:getMark("@v_lianzou_count-turn") >= 50
  end,
  on_cost = function(self, event, target, player, data)
    --确认是否发动技能。
    local room = player.room
    if room:askForSkillInvoke(player,self.name,data) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --判定直到点数大于等于50
    if event == fk.EventPhaseEnd then
      --这里可以后续放限定动画并给大概2500ms的延时+音效。
      local count = 0
      local dummy = Fk:cloneCard("slash")
      while count < 50 do
        local judge = {
          who = player,
          reason = self.name,
          pattern = ".|1~"..(50-count).."|.",
        }
        room:judge(judge)
        local result = judge.card
        count = count + result.number
        if count < 50 then
          dummy:addSubcard(result)
        end
      end
      room:obtainCard(player.id, dummy, true)
    end
  end,

  --刷新时机：手牌结算后，手牌打出结算后（本时机伴随希贝尔上线，与之同步因此删除）
  refresh_events = {fk.CardUseFinished},
  --刷新条件
  --（手牌结算后，手牌打出结算后（这个待定））
  --             触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              被遍历到的角色处于出牌阶段。
  can_refresh = function(self, event, target, player, data)
    -- if not (target == player and player:hasSkill(self.name)) then
    --   return false
    -- end
    return target == player and player:hasSkill(self.name)
    and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    --在满足以下条件的前提下，将牌的点数加入某个mark里。
    -- 卡牌存在，为实体牌, 卡牌点数小于等于13大于0。
    local card = data
    if card.card and card.card.id > 0 and card.card.number <= 13 and card.card.number > 0 then
      room:addPlayerMark(player, "@v_lianzou_count-turn", card.card.number)
    end
  end
}

--------------------------------------------------
--弦羽
--角色马克：抹挑
--------------------------------------------------

local xianyu_xiangluancuxian = General(extension,"xianyu_xiangluancuxian", "chaociyuan", 3, 3, General.Female)
xianyu_xiangluancuxian:addSkill(v_motiao)
xianyu_xiangluancuxian:addSkill(v_lianzou)

Fk:loadTranslationTable{
  ["xianyu_xiangluancuxian"] = "弦羽",
	["&xianyu_xiangluancuxian"] = "弦羽",
	["#xianyu_xiangluancuxian"] = "翔鸾促弦",
	["$xianyu_xiangluancuxian"] = "萌新",
	["designer:xianyu_xiangluancuxian"] = "SunFlower、NSX",
	["cv:xianyu_xiangluancuxian"] = "",
	["illustrator:xianyu_xiangluancuxian"] = "",
	["~xianyu_xiangluancuxian"] = "",
	["v_motiao"] = "抹挑",
	["@@v_motiao_using-turn"] = "抹挑已激活",
	--[":v_motiao"] = "你于出牌阶段内使用牌指定自己为目标之一后，你可以摸一张牌。<br/><font color='#B22222'>使用此技能的回合，你只能造成1点伤害。</font>",
	[":v_motiao"] = "准备阶段，你可以<font color='#A9A9A9'>发动此技能</font>，本回合内你只能造成1点伤害，你使用牌指定自己为目标之一后，摸一张牌。",
  	--[":v_motiao"] = "准备阶段，你可以，本回合内你只能造成1点伤害，你使用牌指定自己为目标之一后，摸一张牌。",
	["v_motiao_choice"] = "你可以发动“抹挑”，本回合使用牌指定自己后摸一张牌，但只能造成1点伤害",
	["$v_motiao1"] = "徵",
	["$v_motiao2"] = "羽",
	["$v_motiao3"] = "宫",
	["$v_motiao4"] = "商",
	["$v_motiao5"] = "角",
	["$v_motiao6"] = "徵",
	["$v_motiao7"] = "羽",
	["$v_motiao8"] = "宫",
	["$v_motiao9"] = "宫（滚奏）",
	["$v_motiao10"] = "徵（滚奏）",
	["v_lianzou"] = "连奏",
	["@v_lianzou_count-turn"] = "连奏蓄力",
	[":v_lianzou"] = "限定技，出牌阶段结束时，若你本阶段内使用的牌点数和≥50，你可以<font color='#A9A9A9'>发动此技能</font>，<font color='#9400D3'>连续判定</font>直到判定牌点数和≥50，你获得<font color='#9400D3'>这些判定牌</font>。",
  	--[":v_lianzou"] = "限定技，出牌阶段结束时，若你本阶段内使用的牌点数和≥50，你可以<font color='#9400D3'>连续判定</font>直到判定牌点数和≥50，你获得<font color='#9400D3'>这些判定牌</font>。",
	["$v_lianzou1"] = "琶音",
	["$v_lianzou2"] = "琶音",
}


--------------------------------------------------
--贵胄
--------------------------------------------------

local v_guizhou = fk.CreateTriggerSkill{
  name = "v_guizhou",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    local ret = target == player and player:hasSkill(self.name) and
      (data.card.trueName == "slash" or data.card.name == "duel" )
    if ret then
      self.target_list = {}
      local room = player.room
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if p.id ~= data.from and p:inMyAttackRange(player) then
          table.insert(self.target_list, p.id)
        end
      end
      return #self.target_list > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#v_guizhou_target:"..data.from.."::"..data.card.name
    local plist, cid = room:askForChooseCardAndPlayers(player, self.target_list, 1, 1, nil, prompt, self.name, true)
    if #plist > 0 then
      self.cost_data = {plist[1], cid}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = self.cost_data[1]
    room:doIndicate(player.id, { to })
    if not data.card:isVirtual() then
      room:sendLog{
        type = "#v_guizhou_log",
        from = data.from,
        to = { to },
        arg = self.name,
        card = { data.card.id },
      }
    elseif data.card:isVirtual() then
      room:sendLog{
        type = "#v_guizhou_virtual_log",
        from = data.from,
        to = { to },
        arg = self.name,
        arg2 = data.card:toLogString(),
      }
    end
    room:throwCard(self.cost_data[2], self.name, player, player)
    TargetGroup:removeTarget(data.targetGroup, player.id)
    TargetGroup:pushTargets(data.targetGroup, to)
  end,
}

--------------------------------------------------
--苦情
--技能马克：
--------------------------------------------------

local v_kuqing = fk.CreateTriggerSkill{
  name = "v_kuqing",
  --赋予控场型技能定义
  anim_type = "control",
  --时机：受到伤害后
  events = {fk.Damaged},
  --触发条件：
  -- 遍历到的角色具有本技能
  -- 伤害大于0，触发时机的角色处于遍历到的角色攻击范围内
  -- 触发时机的角色区域内有牌
  can_trigger = function(self, event, target, player, data)
    local damage = data
    return player:hasSkill(self.name) 
    and damage.damage > 0 and player:inMyAttackRange(target)
    and (not target:isNude())
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#v_kuqing_use:"..target.id
    if (not player:isKongcheng()) then
      local ret = room:askForDiscard(player, 1, 1, false, self.name, true, ".", prompt)
      --需要的话在这里增加技能检测失效
      if #ret > 0 then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForCardChosen(player, target, "he", self.name)
    room:obtainCard(player.id, card, false)
  end,
}

--------------------------------------------------
--诺拉
--角色马克：
--------------------------------------------------

local nuola_canglangzhixin = General(extension,"nuola_canglangzhixin", "RainbowPro", 3, 3, General.Female)
nuola_canglangzhixin:addSkill(v_guizhou)
nuola_canglangzhixin:addSkill(v_kuqing)

Fk:loadTranslationTable{
	["nuola_canglangzhixin"] = "诺拉",
	["&nuola_canglangzhixin"] = "诺拉",
	["#nuola_canglangzhixin"] = "沧浪之心",
	["$nuola_canglangzhixin"] = "一般",
	["designer:nuola_canglangzhixin"] = "NSX",
	["cv:nuola_canglangzhixin"] = "",
	["illustrator:nuola_canglangzhixin"] = "",
	["~nuola_canglangzhixin"] = "",
	["v_guizhou"] = "贵胄",
	[":v_guizhou"] = "你成为【杀】或【决斗】的目标时，你可以弃置一张牌<font color='#A9A9A9'>发动此技能</font>，将此牌转移给一名攻击范围内有你的其他角色。",
	["$v_guizhou"] = "",
  ["~v_guizhou"] = "选择一张牌→选择一名其他角色→点击确定",
  ["#v_guizhou_target"] = "%src 对你使用 %arg，你可以弃置一张牌发动“贵胄”，将此牌转移给其他角色",
	["#v_guizhou_log"] = "由于“%arg”的效果，%from 使用的 %card 目标改为 %to",
	["#v_guizhou_virtual_log"] = "由于“%arg”的效果，%from 使用的 %arg2 目标改为 %to",
	["v_kuqing"] = "苦情",
	[":v_kuqing"] = "你攻击范围内的角色受到伤害后，你可以弃置一张手牌<font color='#A9A9A9'>发动此技能</font>，获得其一张牌。",
	["$v_kuqing"] = "",
	["#v_kuqing_use"] = "你可以弃置一张手牌，对 %src 发动“苦情”",
}

--------------------------------------------------
--幽蓝
--技能马克：缺少七海表情包
--------------------------------------------------

local v_youlan = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_youlan",
  --(非必要）赋予特殊型技能定义
  anim_type = "special",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：受到伤害时，造成伤害时
  events = {fk.DamageInflicted,fk.DamageCaused},
  --触发条件：
  --（受到伤害时）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、牌为实体牌、牌的种类为锦囊牌、造成的伤害大于0。
  --（造成伤害时）造成伤害的来源为遍历到的角色、遍历到的角色具有本技能、牌为实体牌、牌的种类为锦囊牌、造成的伤害大于0。
  can_trigger = function(self, event, target, player, data)
    local damage = data
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self.name) and
        (data.card and data.card.type == Card.TypeTrick) and damage.damage > 0
    elseif event == fk.DamageCaused then
      return target == player and player:hasSkill(self.name) and
        (data.card and data.card.type == Card.TypeTrick)  and damage.damage > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local damage = data
    local room = player.room
    if event == fk.DamageInflicted then
      damage.damage = damage.damage - 1
      if damage.damage <= 0 then
        room:setEmotion(player, "./packages/vupslash/image/anim/skill_nullify")
      end
    elseif event == fk.DamageCaused then
      damage.damage = damage.damage + 1
    end
  end,
}

--------------------------------------------------
--七海幽娴
--角色马克：幽蓝，特性·箭雨未实装
--------------------------------------------------

local qihaiyouxian_zhuangzhilingyun = General(extension, "qihaiyouxian_zhuangzhilingyun", "VirtualDove", 4, 3, General.Agender)
qihaiyouxian_zhuangzhilingyun:addSkill(v_youlan)

Fk:loadTranslationTable{
	["qihaiyouxian_zhuangzhilingyun"] = "七海幽娴",
	["&qihaiyouxian_zhuangzhilingyun"] = "七海幽娴",
	["#qihaiyouxian_zhuangzhilingyun"] = "幽海鸢行",
	["$qihaiyouxian_zhuangzhilingyun"] = "萌新",
	["designer:qihaiyouxian_zhuangzhilingyun"] = "NSX",
	["cv:qihaiyouxian_zhuangzhilingyun"] = "",
	["illustrator:qihaiyouxian_zhuangzhilingyun"] = "",
	["~qihaiyouxian_zhuangzhilingyun"] = "",
	["v_youlan"] = "幽蓝",
	[":v_youlan"] = "锁定技，你受到锦囊牌造成的伤害－1；你使用锦囊牌造成的伤害＋1。",
	["$v_youlan"] = "",
}

--------------------------------------------------
--蓁惹
--技能马克：作为目标疑似会导致雌雄双股剑无效。
--------------------------------------------------

local v_zhenre = fk.CreateTriggerSkill{
  name = "v_zhenre",
  --赋予防御型技能定义
  anim_type = "defensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：目标确定后
  events = {fk.TargetConfirmed},
  --触发条件：目标为玩家、玩家具有本技能、牌的种类为杀、牌的花色为红桃或黑桃。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and
      (data.card.trueName == "slash" and (data.card.suit == Card.Heart or data.card.suit == Card.Spade))
  end,
  on_use = function(self, event, target, player, data)
    table.insert(data.nullifiedTargets, player.id)
  end,
}

--------------------------------------------------
--芳仙
--技能马克：优化芳仙本体技能发动时的描述（可以考虑第一阶段的choice也做成锁定技，然后用askchooseplayer一类的方法插入tips）。
--------------------------------------------------

local v_fangxian_choice = fk.CreateTriggerSkill{
  name = "#v_fangxian_choice",
  --赋予支援型技能定义
  anim_type = "support",
  --时机：阶段变化时
  events = {fk.EventPhaseChanging},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能，下一阶段为摸牌阶段，摸牌阶段未被跳过。
  can_trigger = function(self, event, target, player, data)
    local change = data
    --阶段变化时，实现“是否跳摸牌”的效果。 
    --exist_or_not：用来确认是否跳过对应阶段，类似于以前的Player:isSkipped()
    return target == player and player:hasSkill(self.name) 
    and change.to == Player.Draw and VslUtil.exist_or_not(player, Player.Draw)
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  -- on_cost = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   return true
  --   --end
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --阶段变化时，实现“是否跳摸牌”的效果。
    local change = data
    if change.to == Player.Draw then
        --技能被无效化的效果试作
        --if self:isEffectable(player) then
        room:setPlayerMark(player, "@@v_fangxian-turn", 1)
        --end
        --此处不使用player:skip()而使用return true原因如下：
        --N神原话：触发技被触发的源头为Gamelogic::trigger（这个可以参考文档）
        --根据源码serverplay.lua中play函数的表示（其用于每个阶段的衍生），每个阶段开始时会先检索一次跳过阶段
        --由于其相关概念影响到触发时机，因此影响到了on_use中skip函数的使用
        --新版本说法：时机为change阶段时，跳阶段的检测已经完成，此时把下一个阶段塞进跳阶段列表里无效。
        return true
        --end
      --end
    end
  end,
}
local v_fangxian = fk.CreateTriggerSkill{
  name = "v_fangxian",
  --赋予支援型技能定义
  anim_type = "support",
  --时机：阶段开始时
  events = {fk.EventPhaseStart},
  --触发条件：遍历到的角色处于结束阶段，通过芳仙跳过摸牌阶段。
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player.phase == Player.Finish and player:getMark("@@v_fangxian-turn") > 0 then
      --在场且存活
      --for _, p in ipairs(room:getAlivePlayers()) do
      return true
      --end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --阶段变化时，实现“是否跳摸牌”的效果。
    if player.phase == Player.Finish and player:getMark("@@v_fangxian-turn") > 0 then
      --制作一个囊括所有存活角色的table-targets
      local alives = room:getAlivePlayers()
      local prompt = "#v_fangxian-target"
      local targets = {}
      for _, p in ipairs(alives) do
        table.insert(targets, p.id)
      end
      --to：从targets中选择1个目标，是个值为number的table。
      local to = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name)
      --这里后续可以增加“技能发动者是否可以对对应角色使用技能”的判定，类似于caneffect函数。
      if #to > 0 then
        --通过ID找到对应的ServerPlayer
        local player_to = room:getPlayerById(to[1])
        --指向类特效用函数doIndicate，但执行后由于不明原因在367行报了function的错，不理解。
        --room:doAnimate(1, player:objectName(), to:objectName()) --doAnimate 1:产生一条从前者到后者的指示线
        if player_to ~= player then
          --doindicate的两个参数均为integer类型，一般为角色id
          room:doIndicate(player.id, to)
        end
        room:recover{
          who = player_to,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      else
        player:drawCards(2, self.name)
      end
    end
  end,

  --目前萌以前写的标记一键删除姬还没做出来，因此还是用比较原始的refresh处理。
  -- refresh_events = {fk.EventPhaseStart},
  -- can_refresh = function(self, event, target, player, data)
  --   if not (target == player and player:hasSkill(self.name)) then
  --     return false
  --   end
  --   if event == fk.EventPhaseStart then
  --     return player.phase == Player.NotActive
  --   end
  -- end,
  -- on_refresh = function(self, event, target, player, data)
  --   local room = player.room
  --   room:setPlayerMark(player, "@@v_fangxian-turn", 0)
  -- end
}

-- table.insert(turn_end_clear_mark, "@@v_fangxian-turn")

v_fangxian:addRelatedSkill(v_fangxian_choice)

--------------------------------------------------
--桃水纪
--角色马克：蓁惹，芳仙
--------------------------------------------------

local taoshuiji_fenhuafutao = General(extension, "taoshuiji_fenhuafutao", "individual", 4, 4, General.Female)
taoshuiji_fenhuafutao:addSkill(v_zhenre)
taoshuiji_fenhuafutao:addSkill(v_fangxian)

Fk:loadTranslationTable{
	["taoshuiji_fenhuafutao"] = "桃水纪",
	["&taoshuiji_fenhuafutao"] = "桃水纪",
	["#taoshuiji_fenhuafutao"] = "分花拂桃",
	["$taoshuiji_fenhuafutao"] = "萌新",
	["designer:taoshuiji_fenhuafutao"] = "NSX",
	["cv:taoshuiji_fenhuafutao"] = "",
	["illustrator:taoshuiji_fenhuafutao"] = "",
	["~taoshuiji_fenhuafutao"] = "",
	["v_zhenre"] = "蓁惹",
	[":v_zhenre"] = "锁定技，红桃黑桃花色的【杀】对你无效。",
	["$zhenre"] = "",
	["v_fangxian"] = "芳仙",
	["#v_fangxian_choice"] = "芳仙",
	--由于暂时无法做到将跳过出牌阶段放置于on_cost，因此可能修改技能描述。
	--[":v_fangxian"] = "你可以跳过摸牌阶段<font color='#A9A9A9'>发动此技能</font>，本回合的结束阶段你选择一项：1.摸两张牌；2.令一名角色回复1点体力。",
	[":v_fangxian"] = "你可以<font color='#A9A9A9'>发动此技能</font>，跳过摸牌阶段，本回合的结束阶段你选择一项：1.摸两张牌；2.令一名角色回复1点体力。",
	--[":v_fangxian"] = "你可以跳过摸牌阶段，本回合的结束阶段你选择一项：1.摸两张牌；2.令一名角色回复1点体力。",
	["$v_fangxian"] = "",
	["@@v_fangxian-turn"] = "芳仙",
	["#v_fangxian-target"] = "你可以令一名角色回复1点体力，或令你摸两张牌<br/>操作提示：<br/>①回复体力：选择一名角色→确定<br/>②摸两张牌：取消",
  	--[":mark:&v_fangxian"] = "结束阶段可以摸两张牌或令一名角色回复体力",
}

--------------------------------------------------
--视幻
--------------------------------------------------

local v_shihuan_buff =  fk.CreateMaxCardsSkill{
  name = "#v_shihuan_buff",
  fixed_func = function(self, player)
    if player:getMark("@v_shihuan_card-turn") > 0 then
      return player:getMark("@v_shihuan_card-turn")
    end
  end
}
local v_shihuan = fk.CreateTriggerSkill{
  name = "v_shihuan",
  --赋予控场型技能定义
  anim_type = "control",
  --时机：阶段开始时
  events = {fk.EventPhaseStart},
  --触发条件：遍历到的角色处于准备阶段；遍历全场所有角色，存在角色持有该技能。
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Start
    and player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryRound) < 1
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "v_shihuan_choice:"..target.id.."::"..target:getHandcardNum()
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
    --   end
    -- end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target ~= player then
      --doindicate的两个参数一个为integer，一个为table
      room:doIndicate(player.id, { target.id })
    end
    -- TODO:后续这里做log在提示信息中说明角色手牌上限调整。
    room:sendLog{
      type = "#v_shihuan_log",
      to = {target.id},
      arg = self.name,
      arg2 = math.max(1, target:getHandcardNum()),
    }
    room:setPlayerMark(target, "@v_shihuan_card-turn", math.max(1, target:getHandcardNum()))
    room:setPlayerMark(player, "@@v_shihuan_used-round", 1)
  end,
}

v_shihuan:addRelatedSkill(v_shihuan_buff)

--------------------------------------------------
--可餐
--TODO：锦囊牌显示好结果暂时无法出现，有概率要把所有牌的名字写上去。
--------------------------------------------------

local v_kecan = fk.CreateTriggerSkill{
  name = "v_kecan",
  --赋予负面型技能定义
  anim_type = "negative",
  --时机：受到伤害后
  events = {fk.Damaged},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能，伤害大于0，存在伤害来源，伤害来源存活。
  can_trigger = function(self, event, target, player, data)
    local damage = data
    return target == player and player:hasSkill(self.name) 
    and damage.damage > 0 and damage.from and damage.from:isAlive()
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    --执行判定，判定如为锦囊牌，则触发效果。
    local room = player.room
    local damage = data
    local judge = {
      who = damage.from,
      reason = self.name,
      --TODO:把所有锦囊牌的名字写上去？
      pattern = ".|.|.|.|.|trick",
    }
    room:judge(judge)
    if judge.card.type == Card.TypeTrick then
      room:recover{
        who = damage.from,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
      room:changeMaxHp(player, -1)
    end
  end,
}

--------------------------------------------------
--萨比萌
--角色马克：可餐
--------------------------------------------------

local sabimeng_bimengjushou = General(extension,"sabimeng_bimengjushou", "individual", 6, 6, General.Female)
sabimeng_bimengjushou:addSkill(v_shihuan)
sabimeng_bimengjushou:addSkill(v_kecan)

Fk:loadTranslationTable{
	["sabimeng_bimengjushou"] = "萨比萌",
	["&sabimeng_bimengjushou"] = "萨比萌",
	["#sabimeng_bimengjushou"] = "比萌巨兽",
	["$sabimeng_bimengjushou"] = "简单",
	["designer:sabimeng_bimengjushou"] = "NSX",
	["cv:sabimeng_bimengjushou"] = "",
	["illustrator:sabimeng_bimengjushou"] = "",
	["~sabimeng_bimengjushou"] = "",
	["v_shihuan"] = "视幻",
	["#v_shihuan_buff"] = "视幻",
	["@v_shihuan_card-turn"] = "视幻",
	["@@v_shihuan_used-round"] = "视幻已使用",
	[":v_shihuan"] = "每轮限一次，一名角色的准备阶段，你可以<font color='#A9A9A9'>发动此技能</font>，令其本回合手牌上限等于X。（X为其手牌数且至少为1）",
	["$v_shihuan"] = "",
	["v_shihuan_choice"] = "你可以发动“视幻”，令 %src 本回合的手牌上限变为 %arg",
	["#v_shihuan_log"] = "由于“%arg”的效果，%to 本回合手牌上限变为 %arg2",
	["v_kecan"] = "可餐",
	[":v_kecan"] = "锁定技，你受到伤害后，伤害来源进行一次判定，若结果为锦囊牌，其回复1点体力，你失去1点体力上限。",
	["$v_kecan"] = "",
}

--------------------------------------------------
--蟹袭
--技能马克：
--------------------------------------------------

local v_xiexi = fk.CreateTriggerSkill{
  name = "v_xiexi",
  --赋予特殊型技能定义
  anim_type = "special",
  --时机：手牌结算后
  events = {fk.CardUseFinished},
  --触发条件：结算的牌为红桃牌；遍历的角色存在此技能；当前回合角色及遍历的角色存活；遍历全场所有角色，存在角色持有该技能（据说这条不必要）。
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target:isAlive() and data.card.suit == Card.Heart
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if not target.chained then
      local prompt = "v_xiexi_chain:"..target.id
      --if VslUtil.yes_or_no(player, self.name, prompt) then
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        return true
      end
    elseif target.chained then
      local prompt = "v_xiexi_damage:"..target.id
      --if VslUtil.yes_or_no(player, self.name, prompt) then
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    --遍历全场所有角色，对持有此技能的角色询问其是否发动技能。
    local room = player.room
    if target ~= player then
      --doindicate的两个参数一个为integer，一个为table
      room:doIndicate(player.id, { target.id })
    end
    if not target.chained then
      target:setChainState(true)
    elseif target.chained then
      room:damage{
        from = player,
        to = target,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = self.name,
      }
    end
  end,
}

--------------------------------------------------
--归影
--技能马克：
--------------------------------------------------

local v_guiying = fk.CreateTriggerSkill{
  name = "v_guiying",
  --赋予控场型技能定义
  anim_type = "control",
  --时机：角色离场时
  events = {fk.Death},
  --触发条件：触发时机的角色存在、触发时机的角色为遍历到的角色、触发时机的角色具有本技能。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name,false,true)
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  on_cost = function(self, event, target, player, data)
    --if self:isEffectable(player) then
    --制作一个囊括所有存活角色的table-targets，可以增加“技能发动者是否可以对对应角色使用技能”的判定，类似于caneffect函数。
    local room = player.room
    local alives = room:getAlivePlayers()
    local prompt = "#v_guiying_invoke"
    local targets = {}
    for _, p in ipairs(alives) do
      table.insert(targets, p.id)
    end
    --to：从targets中选择1个目标，是个值为number的table。
    local to = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    --end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --通过ID找到对应的ServerPlayer
    local player_to = room:getPlayerById(self.cost_data)
    player_to:turnOver()
    local dummy = Fk:cloneCard("slash")
    dummy:addSubcards(player:getCardIds(Player.Hand))
    dummy:addSubcards(player:getCardIds(Player.Equip))
    dummy:addSubcards(player:getCardIds(Player.Judge))
    room:obtainCard(player_to.id, dummy, false,fk.ReasonPrey)
  end,
}

--------------------------------------------------
--阮卿言
--角色马克：
--------------------------------------------------

local ruanqingyan_hushanguiying = General(extension,"ruanqingyan_hushanguiying", "individual", 3, 3, General.Female)
ruanqingyan_hushanguiying:addSkill(v_xiexi)
ruanqingyan_hushanguiying:addSkill(v_guiying)

Fk:loadTranslationTable{
	["ruanqingyan_hushanguiying"] = "阮卿言",
	["&ruanqingyan_hushanguiying"] = "阮卿言",
	["#ruanqingyan_hushanguiying"] = "狐山归影",
	["$ruanqingyan_hushanguiying"] = "简单",
	["designer:ruanqingyan_hushanguiying"] = "探求黎明者",
	["cv:ruanqingyan_hushanguiying"] = "",
	["illustrator:ruanqingyan_hushanguiying"] = "",
	["~ruanqingyan_hushanguiying"] = "",
	["v_xiexi"] = "蟹袭",
	[":v_xiexi"] = "一名角色使用红桃牌结算结束后，你可以<font color='#A9A9A9'>发动此技能</font>，若其未横置则横置之，否则对其造成1点火焰伤害。",
	["$v_xiexi"] = "",
  	--["#v_xiexi_invoke"] = "你可以发动“蟹袭”，横置 %src，若其已横置，则对 %src 造成1点火焰伤害",
	["v_xiexi_chain"] = "你可以发动“蟹袭”，横置 %src",
	["v_xiexi_damage"] = "你可以发动“蟹袭”，对 %src 造成1点火焰伤害",
	["v_guiying"] = "归影",
	[":v_guiying"] = "你离场时，你可以指定一名其他角色，<font color='#A9A9A9'>发动此技能</font>，其翻面然后获得你区域内的所有牌。",
	["$v_guiying"] = "",
	["#v_guiying_invoke"] = "你可以指定一名角色发动“归影”，令其翻面并获得你的所有牌",
}

--------------------------------------------------
--奇虑
--------------------------------------------------

local v_qilvbuff = fk.CreateTargetModSkill{
  name = "#v_qilvbuff",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(self.name) and skill.trueName == "slash_skill" 
      and scope == Player.HistoryPhase then
      return -1
    end
  end,
}
local v_qilv = fk.CreateTriggerSkill{
  name = "v_qilv",
  --赋予输出型技能定义
  anim_type = "offensive",
  --时机：阶段变化时
  events = {fk.CardUseFinished},
  --触发条件：
  -- 触发时机的角色为遍历到的角色、遍历到的角色具有本技能，
  -- 使用的牌为锦囊牌，遍历到的角色可以使用杀。
  can_trigger = function(self, event, target, player, data)
    local slash = Fk:cloneCard("slash")
    return target == player and player:hasSkill(self.name) 
    and data.card.type == Card.TypeTrick and (not player:prohibitUse(slash))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    -- local targets = table.filter(room:getOtherPlayers(player), function(p)
    --   return p
    -- end)
    local targets = {}
    local other = room:getOtherPlayers(player)
    local slash = Fk:cloneCard("slash")
    for _, p in ipairs(other) do
      if player:inMyAttackRange(p) and (not player:isProhibited(p, slash)) then
        table.insert(targets, p.id)
      end
    end
    local p = room:askForChoosePlayers(player, targets, 1, 1, "#v_qilv_askforslash", self.name)
    if #p > 0 then
      self.cost_data = p[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    --阶段变化时，实现“是否跳出牌”的效果。
    local slash = Fk:cloneCard("slash")
    local new_use = {} ---@type CardUseStruct
    new_use.from = player.id
    --技能马克：可能会存在类似于知更酱多目标BUG的问题
    new_use.tos = { { tar.id } }
    new_use.card = slash
    new_use.skillName = self.name
    --测试skillName是否有效
    --print(new_use.skillName)
    room:useCard(new_use)
  end,
}
v_qilv:addRelatedSkill(v_qilvbuff)

--------------------------------------------------
--无前Namae
--------------------------------------------------

local wuqian_daweiba = General(extension,"wuqian_daweiba", "individual", 4, 4, General.Male)
wuqian_daweiba:addSkill(v_qilv)

Fk:loadTranslationTable{
	["wuqian_daweiba"] = "无前Namae",
	["&wuqian_daweiba"] = "无前",
	["#wuqian_daweiba"] = "大尾巴",
	["$wuqian_daweiba"] = "简单",
	["designer:wuqian_daweiba"] = "NSX",
	["cv:wuqian_daweiba"] = "",
	["illustrator:wuqian_daweiba"] = "",
	["~wuqian_daweiba"] = "",
	["v_qilv"] = "奇虑",
	["#v_qilvbuff"] = "奇虑",
	[":v_qilv"] = "你使用【杀】的次数上限－1。你使用锦囊牌结算结束后，你可以视为使用一张【杀】。",
	["#v_qilv_askforslash"] = "你可以视为使用一张【杀】<br/>提示：选择此【杀】的目标角色→确定",
}

--------------------------------------------------
--自愈
--------------------------------------------------

local v_ziyu = fk.CreateTriggerSkill{
  name = "v_ziyu",
  --赋予支援型技能定义
  anim_type = "support",
  --时机：阶段开始时，受到伤害后
  events = {fk.EventPhaseStart, fk.Damaged},
  --触发条件：
  --（阶段开始时）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、本阶段为结束阶段、遍历角色体力值不为全场唯一最高。
  --（受到伤害后）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、受到伤害的角色为遍历到的角色、遍历角色体力值不为全场唯一最高。
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local damage = data
    --获取当前游戏除遍历到的角色外其他角色体力最大值。
    local other = room:getOtherPlayers(player)
    local other_max_hp = -999
    for _, p in ipairs(other) do
      if p.hp > other_max_hp then
        other_max_hp = p.hp
      end
    end
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self.name) 
      and player.phase == Player.Finish and player.hp <= other_max_hp
    elseif event == fk.Damaged then
      return target == player and player:hasSkill(self.name) and  damage.to == player and player.hp <= other_max_hp
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {} ---@type JudgeStruct
    judge.who = player
    --这一条的意思是，出现黑桃花色条件后显示判定成功的特效
    judge.pattern = ".|.|spade"
    judge.reason = self.name
    room:judge(judge)
    if judge.card.suit == Card.Spade then
      --考虑到本作存在治疗过量概念，不需要角色受伤也可触发回复效果。
      --if player:isWounded() then 
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
    end
  end,
}

--------------------------------------------------
--嗜血
--------------------------------------------------

local v_shixue = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_shixue",
  --(非必要）赋予支援型技能定义
  anim_type = "support",
  --时机：造成伤害后
  events = {fk.Damage},
  --触发条件：
  --存在触发时机的角色、触发时机的角色为遍历到的角色、遍历到的角色具有本技能、造成伤害的角色为遍历到的角色、造成伤害的卡牌颜色为黑色。
  can_trigger = function(self, event, target, player, data)
    local damage = data
    return target and target == player and player:hasSkill(self.name) and
        damage.from == player and damage.card.color == Card.Black
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  on_cost = function(self, event, target, player, data)
    --if self:isEffectable(player) then
    local room = player.room
    for i = 1, data.damage do
      local choiceList = {}
      if player:isWounded() then 
        table.insert(choiceList, "recover_1")
      end
      table.insert(choiceList, "draw_1")
      table.insert(choiceList, "cancel")
      local choice = room:askForChoice(player, choiceList, self.name)
      if choice == "cancel" then
        break
      elseif choice == "recover_1" then
        self.cost_data = 1
      elseif choice == "draw_1" then
        self.cost_data = 2
      end
      return true
    end
    --end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == 1 then
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
    elseif self.cost_data == 2 then
      player:drawCards(1, self.name)
    end
  end,
}

--------------------------------------------------
--月下暗影
--------------------------------------------------

local yuexiaanying_juexingxuezu = General(extension,"yuexiaanying_juexingxuezu", "individual", 3, 5, General.Bigender)
yuexiaanying_juexingxuezu:addSkill(v_ziyu)
yuexiaanying_juexingxuezu:addSkill(v_shixue)

Fk:loadTranslationTable{
	["yuexiaanying_juexingxuezu"] = "月下暗影",
	["&yuexiaanying_juexingxuezu"] = "月下暗影",
	["#yuexiaanying_juexingxuezu"] = "觉醒血族",
	["$yuexiaanying_juexingxuezu"] = "简单",
	["designer:yuexiaanying_juexingxuezu"] = "月下暗影",
	["cv:yuexiaanying_juexingxuezu"] = "",
	["illustrator:yuexiaanying_juexingxuezu"] = "",
	["~yuexiaanying_juexingxuezu"] = "",
	["v_ziyu"] = "自愈",
	[":v_ziyu"] = "<font color='#9400D3'>结束阶段/你受到伤害后</font>，若你体力值不为全场唯一最高，你可以<font color='#A9A9A9'>发动此技能</font>，进行一次判定，若结果为黑桃，你回复1点体力。",
	["$v_ziyu"] = "",
	["v_shixue"] = "嗜血",
	[":v_shixue"] = "你使用黑色牌造成1点伤害后可以<font color='#A9A9A9'>发动此技能</font>，回复1点体力或摸一张牌。",
	["$v_shixue"] = "",
}

--------------------------------------------------
--忆狩
--技能马克：死了之后疑似还能发动忆狩。
--------------------------------------------------

local v_yishou_slash = fk.CreateTargetModSkill{
  name = "#v_yishou_slash",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase and player:getMark("v_yishou_active-turn") > 0 then
      return player:getMark("v_yishou_active-turn")
    end
  end,
}
local v_yishou_mark = fk.CreateTriggerSkill{
  name = "#v_yishou_mark",
  --赋予卖血型技能定义
  anim_type = "masochism",
  --时机：阶段开始时，受到伤害后，摸牌时
  events = {fk.EventPhaseStart, fk.Damaged},
  --触发条件：
  --（阶段开始时）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、本阶段为结束阶段、遍历到的角色存在且存活且体力>=1。
  --（受到伤害后）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、受到伤害的角色为遍历到的角色、遍历到的角色存在且存活。
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local damage = data
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self.name) 
      and player.phase == Player.Finish and player.hp >= 1
    elseif event == fk.Damaged then
      return target == player and player:hasSkill(self.name) and damage.to == player
      and damage.damage >= 1
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --如果扳机为受到伤害后，根据体力值触发技能；否则正常触发。
    if event == fk.Damaged then
      for i = 1, data.damage do
        local prompt = "v_yishou_damage"
        local room = player.room
        if (not player:isNude()) then
          local ret = room:askForDiscard(player, 1, 1, true, self.name, true, ".", prompt)
          --需要的话在这里增加技能检测失效
          if #ret > 0 then
          --if room:askForDiscard(player, 1, 1, true, self.name, true) then
            return true
          end
        end
      end
    elseif event == fk.EventPhaseStart then
      --需要的话在这里增加技能检测失效;非锁定技想强制发动这里用个true就好啦
      local prompt = "v_yishou_end"
      --if VslUtil.yes_or_no(player, self.name, prompt) then
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        --尝试了一下，这里不能跳阶段，失败的话只能耦合到on_use了。
        room:loseHp(player, 1, self.name)
        --大概要在这里做一个离场与否的判定，防止离场者技能继续发动。
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:addPlayerMark(player, "@v_yishou_count", 1)
    elseif event == fk.Damaged then
      room:addPlayerMark(player, "@v_yishou_count", 1)
    end
  end,
}
local v_yishou = fk.CreateTriggerSkill{
  name = "v_yishou",
  --赋予卖血型技能定义
  anim_type = "masochism",
  --时机：摸牌时
  events = {fk.DrawNCards},
  --触发条件：
  --（摸牌）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、某个标记大于等于1、存在摸牌阶段。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getMark("v_yishou_active-turn") > 0
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local y = 2*player:getMark("v_yishou_active-turn")
    data.n = data.n + y
  end,
  refresh_events = {fk.EventPhaseChanging},
  can_refresh = function(self, event, target, player, data)
    return (data.from == Player.NotActive and data.to ~= Player.NotActive and target == player) 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local x = player:getMark("@v_yishou_count")
    if x > 0 then
      room:sendLog{
        type = "#v_yishou_log",
        from = player.id,
        arg = 2*x,
        arg2 = x,
      }
      room:setPlayerMark(player, "v_yishou_active-turn", x)
      room:setPlayerMark(player, "@v_yishou_count", 0)
    end
  end,
}

v_yishou:addRelatedSkill(v_yishou_mark)
v_yishou:addRelatedSkill(v_yishou_slash)

--------------------------------------------------
--祭血
--技能马克：
--------------------------------------------------

local v_jixue = fk.CreateActiveSkill{
  name = "v_jixue",
  anim_type = "support",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  --target_num = 0,
  --card_num = 0,
  card_filter = function(self, to_select, selected, selected_targets)
    return false
  end,
  on_use = function(self, room, effect)
    --local players = room.players
    local from = room:getPlayerById(effect.from)
    --从两个区域换红色牌
    --local dummy = Fk:cloneCard("slash")
    local cards = {}
    local cards_throw = {}
    local hand = from:getCardIds(Player.Hand)
    local equip = from:getCardIds(Player.Equip)
    --print(hand)
    --print(equip)
    for _,p in ipairs(hand) do
      table.insert(cards, p)
    end
    for _,p in ipairs(equip) do
      table.insert(cards, p)
    end
    for _,p in ipairs(cards) do
      local card_now = Fk:getCardById(p)
      --这里后续可以追加玩家不可以弃置这张牌的判定，类似于鸡肋
      if card_now.color == Card.Red then
        --dummy:addSubcard(card_now)
        table.insert(cards_throw, p)
      end
    end
    --local x = #(dummy.subcards)
    local x = #(cards_throw)
    --print(x)
    if x > 0 then
      room:throwCard(cards_throw, self.name, from, from)
    end
    for i = 1, x do
      local choiceList = {}
      if from:isWounded() then 
        table.insert(choiceList, "recover_1")
      end
      table.insert(choiceList, "draw_1")
      local choice = room:askForChoice(from, choiceList, self.name)
      if choice == "recover_1" then
        room:recover{
          who = from,
          num = 1,
          recoverBy = from,
          skillName = self.name,
        }
      elseif choice == "draw_1" then
        from:drawCards(1, self.name)
      end
    end
  end,
}

--------------------------------------------------
--辻蓝佳音瑠
--角色马克：动画未实装
--------------------------------------------------

local laila_xuelie = General(extension,"laila_xuelie", "individual", 3, 3, General.Female)
laila_xuelie:addSkill(v_yishou)
laila_xuelie:addSkill(v_jixue)

Fk:loadTranslationTable{
	["laila_xuelie"] = "辻蓝佳音瑠",
	["&laila_xuelie"] = "莱拉",
	["#laila_xuelie"] = "血·猎",
	["designer:laila_xuelie"] = "Vup杀制作组",
	["cv:laila_xuelie"] = "",
	["illustrator:laila_xuelie"] = "",
	["~laila_xuelie"] = "",
	["v_yishou"] = "忆狩",
	["#v_yishou_mark"] = "忆狩",
	["@v_yishou_count"] = "忆狩",
	[":v_yishou"] = "<font color='#9400D3'>结束阶段/当你受到1点伤害后</font>，你可以 <font color='#9400D3'>失去1点体力/弃置一张牌</font> <font color='#A9A9A9'>发动此技能</font>，你下回合的通常摸牌数＋2、使用【杀】的次数上限＋1。",
	["v_yishou_end"] = "你可以失去1点体力发动“忆狩”，下回合你多摸2张牌、可以多使用1张杀",
	["v_yishou_damage"] = "你可以弃置一张牌发动“忆狩”，下回合你多摸2张牌、可以多使用1张杀",
	["#v_yishou_log"] = "由于“<b><font color='yellow'>忆狩</font></b>”的效果，%from 本回合通常摸牌数+%arg，使用杀的次数上限+%arg2",
	["v_jixue"] = "祭血",
	[":v_jixue"] = "限定技，出牌阶段，你可以弃置你的所有红色牌，每以此法弃置一张牌，你回复1点体力或摸一张牌。",
}

--------------------------------------------------
--娇惰
--技能马克：
-- Q1: 这个技能是什么意思？可以简单概括一下吗？
-- A1: 一般来说是以下效果：
-- ①你可以跳过判定阶段，摸牌阶段结束后弃置两张牌
-- ②你可以跳过摸牌阶段，出牌阶段结束后将手牌数补充至与跳过摸牌阶段时相同
-- ③你可以跳过出牌阶段，弃牌阶段结束后将手牌数补充至与跳过出牌阶段时相同

-- Q2: 至多摸至X张，这个上限会让我弃牌吗？
-- A2: 不会。如至多摸至5张，将手牌从6张调整至10张，则不会摸牌或弃牌。

-- Q3: 【乐不思蜀】对风野慵生效后，跳过摸牌阶段是什么效果？
-- A3: 跳过摸牌阶段与出牌阶段，弃牌阶段结束后将手牌数调整至与摸牌阶段相同。

-- Q4: 濑川绪良发动“奇遇”令风野慵于回合外执行一个出牌阶段，此时用“娇惰”跳过，会发生什么？
-- A4: 于风野慵的下个回合的准备阶段执行后，将手牌数调整至与跳过这个额外出牌阶段时相同。
--------------------------------------------------

local v_jiaoduo = fk.CreateTriggerSkill{
  name = "v_jiaoduo",
  --赋予特殊型技能定义
  anim_type = "special",
  --时机：阶段变化时，阶段结束时
  events = {fk.EventPhaseChanging, fk.EventPhaseEnd},
  --触发条件：
  --（阶段变化时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --             本回合只使用过一次技能；
  --             被遍历到的角色处于判定/摸牌/出牌阶段；
  --             被遍历到的角色存在对应阶段。
  --（阶段结束时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              在上个阶段使用了此技能（通过标记完成）。
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseChanging then
      local change = data
      --判定区如无牌，则不做判定区处理。
      local cards = {}
      local hand = player:getCardIds(Player.Judge)
      for _,p in ipairs(hand) do
        table.insert(cards, p)
      end
      local x = #(cards)
      return target == player and player:hasSkill(self.name)
      and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
      and ((change.to == Player.Judge and x > 0) or change.to == Player.Draw or change.to == Player.Play)
      and VslUtil.exist_or_not(player, change.to)
    elseif event == fk.EventPhaseEnd then
      return target == player and player:hasSkill(self.name)
      and player:getMark("v_jiaoduo_using-turn") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    --获取本阶段手牌数，确认是否跳过本阶段。
    if event == fk.EventPhaseChanging then
      local room = player.room
      local change = data
      local prompt = "#v_jiaoduo_choice:::"..VslUtil.phase_string(change.to)..":"..0
      --print(prompt)
      local cards = {}
      local hand = player:getCardIds(Player.Hand)
      for _,p in ipairs(hand) do
        table.insert(cards, p)
      end
      local x = #(cards)
      if x > 0 then
        if x > player.maxHp then
          x = player.maxHp
        end
        prompt = "#v_jiaoduo_choice:::"..VslUtil.phase_string(change.to)..":"..x
      end
      if room:askForSkillInvoke(player, self.name, data, prompt) then
      --if VslUtil.yes_or_no(player, self.name, prompt) then
        --尝试了一下，这里不能跳阶段，失败的话只能耦合到on_use了。
        --player:skip(change.to)
        return true
      end
    --满足技能发动要求后，锁定发动。
    elseif event == fk.EventPhaseEnd and (player:getMark("@v_jiaoduo_card-turn") > 0 or player:getMark("@@v_jiaoduo_nocard-turn") > 0) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --以on_cost中跳过阶段为代价，为风野提供标签以触发后续技能。
    --一种标签为无手牌，另一种标签为手牌数，这种区分方式是因为需要将手牌数标签为0的情况视作未触发而非手牌为0.
    if event == fk.EventPhaseChanging then
      local cards = {}
      local hand = player:getCardIds(Player.Hand)
      for _,p in ipairs(hand) do
        table.insert(cards, p)
      end
      local x = #(cards)
      room:setPlayerMark(player, "v_jiaoduo_using-turn", 1)
      if x > 0 then
        room:setPlayerMark(player, "@v_jiaoduo_card-turn", x)
      else
        room:setPlayerMark(player, "@@v_jiaoduo_nocard-turn", 1)
      end
      return true
    elseif event == fk.EventPhaseEnd then
      --清空使用状态，将之前记下来的手牌数转录到local变量z中
      room:setPlayerMark(player, "v_jiaoduo_using-turn", 0)
      local z = 0
      if player:getMark("@@v_jiaoduo_nocard-turn") > 0 then
        room:setPlayerMark(player, "@@v_jiaoduo_nocard-turn", 0)
      elseif player:getMark("@v_jiaoduo_card-turn") > 0 then
        z = player:getMark("@v_jiaoduo_card-turn")
        room:setPlayerMark(player, "@v_jiaoduo_card-turn", 0)
      end
      --现有手牌小于/大于之前记录值之后的处理。
      if player:getHandcardNum() < math.min(player.maxHp, z) then
        local a = math.min(player.maxHp, z) - player:getHandcardNum()
        player:drawCards(a, self.name)
      elseif player:getHandcardNum() > z then
        local a = player:getHandcardNum() - z
        room:askForDiscard(player, a, a, false, self.name, false)
      end
    end
  end,
}

--------------------------------------------------
--风野慵
--角色马克：
--------------------------------------------------

local fengyeyong_youhemingling = General(extension,"fengyeyong_youhemingling", "individual", 4, 4, General.Female)
fengyeyong_youhemingling:addSkill(v_jiaoduo)

Fk:loadTranslationTable{
  ["fengyeyong_youhemingling"] = "风野慵",
	["&fengyeyong_youhemingling"] = "风野慵",
	["#fengyeyong_youhemingling"] = "幽河冥灵",
	["$fengyeyong_youhemingling"] = "一般",
	["designer:fengyeyong_youhemingling"] = "Tangentle",
	["cv:fengyeyong_youhemingling"] = "",
	["illustrator:fengyeyong_youhemingling"] = "",
	["~fengyeyong_youhemingling"] = "",
  	["v_jiaoduo"] = "娇惰",
	--[":v_jiaoduo"] = "每回合限一次，你可以跳过 <font color='#9400D3'>判定/摸牌/出牌</font> 阶段<font color='#A9A9A9'>发动此技能</font>，本回合你的下一个阶段结束时，将手牌数调整至与此技能发动时相同（至多摸至体力上限张数）。",
  	[":v_jiaoduo"] = "每回合限一次，你可以<font color='#A9A9A9'>发动此技能</font>，跳过 <font color='#9400D3'>判定/摸牌/出牌</font> 阶段，本回合你的下一个阶段结束时，将手牌数调整至与此技能发动时相同（至多摸至体力上限张数）。",
	--[":v_jiaoduo"] = "每回合限一次，你可以跳过 <font color='#9400D3'>判定/摸牌/出牌</font> 阶段，本回合你的下一个阶段结束时，将手牌数调整至与此技能发动时相同（至多摸至体力上限张数）。",
  	["$v_jiaoduo"] = "",
  	["@v_jiaoduo_card-turn"] = "娇惰",
	["@@v_jiaoduo_nocard-turn"] = "无手牌",
  	["#v_jiaoduo_choice"] = "你可以跳过 %arg 阶段发动“娇惰”，下个阶段结束时将手牌数调整至 %arg2",
	--["v_jiaoduo:choice"] = "你可以跳过 %src 阶段发动“娇惰”，下个阶段结束时将手牌数调整至 %dest",
}

--------------------------------------------------
--辨识
--技能马克：
--------------------------------------------------

local v_bianshi = fk.CreateActiveSkill{
  name = "v_bianshi",
  --赋予摸牌型技能定义
  anim_type = "drawcard",
  --可用条件：
  --出牌阶段限一次
  --角色手牌数<4+角色装备数
  can_use = function(self, player)
    local hands = {}
    local equips = {}
    local hand = player:getCardIds(Player.Hand)
    local equip = player:getCardIds(Player.Equip)
    for _,p in ipairs(hand) do
      table.insert(hands, p)
    end
    for _,p in ipairs(equip) do
      table.insert(equips, p)
    end
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    and #(hands) < 4 + #(equips)
  end,
  card_filter = function(self, to_select, selected, selected_targets)
    return false
  end,
  on_use = function(self, room, effect)
    local players = room.players
    --记录手牌区及装备区的牌。
    local hands = {}
    local equips = {}
    local pp = nil
    --通过是否处于出牌阶段确认是否是该玩家。
    for _,p in ipairs(players) do
      if p.phase == Player.Play then
        pp = p
      end
    end
    local hand = pp:getCardIds(Player.Hand)
    local equip = pp:getCardIds(Player.Equip)
    for _,p in ipairs(hand) do
      table.insert(hands, p)
    end
    for _,p in ipairs(equip) do
      table.insert(equips, p)
    end

    local x = 4 + #(equips)
    local draw_num = x - #(hands)
    if draw_num > 0 then
      room:sendLog{
        type = "#v_bianshi",
        from = pp.id,
        arg = self.name,
        arg2 = x
      }
      room:drawCards(pp, draw_num, self.name, top)
      room:askForDiscard(pp, draw_num, draw_num, true, self.name, false)
    end
  end,
}

--------------------------------------------------
--成长
--------------------------------------------------

local v_chengzhang = fk.CreateTriggerSkill{
  name = "v_chengzhang",
  --赋予支援型技能定义
  anim_type = "support",
  --时机：体力回复后
  events = {fk.HpRecover},
  --触发条件：
  --（摸牌）造成回复的角色为遍历到的角色、遍历到的角色具有本技能、触发时机的角色体力==1。
  can_trigger = function(self, event, target, player, data)
    return data.recoverBy == player and player:hasSkill(self.name) 
    and target.hp == 1
  end,
  -- on_cost = function(self, event, target, player, data)
  --   return true
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --记录牌堆及弃牌堆的装备牌。
    local equips = {}
    --这里没摸到牌堆/弃牌堆的牌
    local draw = room.draw_pile
    local discard = room.discard_pile
    for _,p in ipairs(draw) do
      local card = Fk:getCardById(p)
      --（后续可以补充isavailable判定确保这个装备是可以被玩家装备的，如果出现玩家因为无法使用或装备区封印穿不上去的情况可以噶了。)
      if card.type == Card.TypeEquip and (not player:prohibitUse(card)) then
        table.insert(equips, p)
      end
    end
    for _,p in ipairs(discard) do
      local card = Fk:getCardById(p)
      --（后续可以补充isavailable判定确保这个装备是可以被玩家装备的，如果出现玩家因为无法使用或装备区封印穿不上去的情况可以噶了。)
      if card.type == Card.TypeEquip and (not player:prohibitUse(card)) then
        table.insert(equips, p)
      end
    end
    if #(equips) > 0 then
      local x = #(equips)
      local c = math.random(1, x)
      local card = equips[c]
      --这种函数可以从表中随机选n个元素并返回一张表，如果n是nil，那么返回的就不是表而是单个元素
      --local card = table.random(equips, nil)
      local new_use = {} ---@type CardUseStruct
      new_use.from = player.id
      --技能马克：可能会存在类似于知更酱多目标BUG的问题
      new_use.tos = { { player.id } }
      new_use.card = Fk:getCardById(card)
      new_use.skillName = self.name
      room:useCard(new_use)
    end
  end,
}

--------------------------------------------------
--小毛
--角色马克：
--------------------------------------------------

local xiaomao_lairikeqi = General(extension,"xiaomao_lairikeqi", "individual", 4, 4, General.Female)
xiaomao_lairikeqi:addSkill(v_bianshi)
xiaomao_lairikeqi:addSkill(v_chengzhang)

Fk:loadTranslationTable{
	["xiaomao_lairikeqi"] = "小毛",
	["&xiaomao_lairikeqi"] = "小毛",
	["#xiaomao_lairikeqi"] = "来日可期",
	["$xiaomao_lairikeqi"] = "简单",
	["designer:xiaomao_lairikeqi"] = "NSX",
	["cv:xiaomao_lairikeqi"] = "",
	["illustrator:xiaomao_lairikeqi"] = "",
	["~xiaomao_lairikeqi"] = "",
	["v_bianshi"] = "辨识",
	[":v_bianshi"] = "出牌阶段限一次，若你手牌数小于X张，你可以将手牌数<font color='#9400D3'>补至X</font>张，然后弃置<font color='#9400D3'>等量</font>张牌。(X为你装备区内的牌数+4)",
	["$v_bianshi"] = "",
	["#v_bianshi"] = "由于“%arg”的效果，%from 将手牌数调整为 %arg2 张",
	["v_chengzhang"] = "成长",
	[":v_chengzhang"] = "你令一名角色回复体力后，若其体力值为1，你可以<font color='#A9A9A9'>发动此技能</font>，随机使用牌堆、弃牌堆中的一张装备牌。",
	--[":v_chengzhang"] = "你令一名角色回复体力后，若其体力值为1，你可以随机使用牌堆、弃牌堆中的一张装备牌。",
	["$v_chengzhang"] = "",
}

--------------------------------------------------
--采集
--------------------------------------------------

local v_caiji = fk.CreateTriggerSkill{
  name = "v_caiji",
  --赋予支援型技能定义
  anim_type = "support",
  --时机：阶段开始时
  events = {fk.EventPhaseStart},
  --触发条件：触发时机的角色为遍历到的角色、遍历到的角色具有本技能，
  -- 遍历到的角色处于结束阶段，本回合未造成伤害，
  -- 遍历到的角色手牌数<4，遍历到的角色手牌数=体力值。
  can_trigger = function(self, event, target, player, data)
    --阶段变化时，实现“是否跳出牌”的效果。
    --exist_or_not：用来确认是否跳过对应阶段，类似于以前的Player:isSkipped()
    return target == player and player:hasSkill(self.name) 
    and player.phase == Player.Finish and player:getMark("#turn_damage-turn") == 0
    and player:getHandcardNum() < 4 and player.hp == player:getHandcardNum()
  end,
  -- on_trigger = function(self, event, target, player, data)
  --   --if self:isEffectable(player) then
  --   self:doCost(event, target, player, data)
  --   --end
  -- end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "v_caiji_choice:::"..math.max(0, 4-player:getHandcardNum())
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(math.max(0, 4-player:getHandcardNum()),self.name, top)
  end,
}

--------------------------------------------------
--进化
--技能马克：
-- TODO：
-- 应援暂时不用管，等后续实装类似的通用技能再说。
--------------------------------------------------

local v_jinhua = fk.CreateTriggerSkill{
  name = "v_jinhua",
  --赋予特殊型技能定义
  anim_type = "special",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：目标确定后，卡牌移动后
  events = {fk.TargetSpecified, fk.AfterCardsMove},
  --触发条件：
  --（目标确定后）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --             使用的牌牌名为桃；
  --             被使用牌的目标体力<=0；
  --             被遍历到的角色不存在对应标记1。
  --（卡牌移动后）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；条件1及条件2满足其中之一。
  --             （未完成）条件1：被遍历到的角色不存在对应标记2；被遍历到的角色处于回合外；
  --             遍历所有的牌牌移向被遍历到的角色；牌移向手牌区；牌移动的技能名不为“应援”（后补）。
  --             条件2：被遍历到的角色不存在对应标记2；被遍历到的角色装备区牌数量>=3。
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      local room = player.room
      local targets = data
      local jinhua_tar = AimGroup:getAllTargets(targets.tos)
      return target == player and player:hasSkill(self.name)
      and data.card.name == "peach"
      and room:getPlayerById(jinhua_tar[1]).hp <= 0
      and player:getMark("v_jinhua_1") == 0
    elseif event == fk.AfterCardsMove then
      local equips = player:getCardIds(Player.Equip)
      local ret21 = false
      for _, d in ipairs(data) do
        if d.toArea == Player.Hand and d.to == player.id then
        --- and d.skillName ~= "LDyingyuan" 
          ret21 = true
        end
      end
      local ret2 = player:getMark("v_jinhua_2") == 0 and player.phase == Player.NotActive and ret21
      local ret3 = player:getMark("v_jinhua_3") == 0 and #equips >= 3
      return player:hasSkill(self.name) and ( ret2 or ret3 )
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --增加对应的标记(暂时通过手牌进入的区域划分)。
    if event == fk.TargetSpecified then
      room:addPlayerMark(player, "v_jinhua_1", 1)
    elseif event == fk.AfterCardsMove then
      local ret22 = false
      for _, d in ipairs(data) do
        if d.toArea == Player.Hand then
          ret22 = true
        end
      end
      if ret22 == true then
        room:addPlayerMark(player, "v_jinhua_2", 1)
      elseif ret22 == false then
        room:addPlayerMark(player, "v_jinhua_3", 1)
      end
    end
    --增加一点体力上限，回复一点体力。
    room:changeMaxHp(player, 1)
    room:recover{
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name,
    }
  end,
}

--------------------------------------------------
--奈伊
--------------------------------------------------

local naiyi_chongqunzhixin = General(extension, "naiyi_chongqunzhixin", "individual", 3, 2, General.Agender)
naiyi_chongqunzhixin:addSkill(v_caiji)
naiyi_chongqunzhixin:addSkill(v_jinhua)

Fk:loadTranslationTable{
	["naiyi_chongqunzhixin"] = "奈伊",
	["&naiyi_chongqunzhixin"] = "奈伊",
	["#naiyi_chongqunzhixin"] = "虫群之心",
	["$naiyi_chongqunzhixin"] = "一般",
	["designer:naiyi_chongqunzhixin"] = "月音风源",
	["cv:naiyi_chongqunzhixin"] = "",
	["illustrator:naiyi_chongqunzhixin"] = "",
	["~naiyi_chongqunzhixin"] = "",
	["v_caiji"] = "采集",
	[":v_caiji"] = "结束阶段，若你的手牌数=体力值且本回合你未造成过伤害，你可以<font color='#A9A9A9'>发动此技能</font>，将手牌数补至4张。",
	["$v_caiji"] = "",
	["v_caiji_choice"] = "你可以发动“采集”，摸 %arg 张牌",
	["v_jinhua"] = "进化",
	[":v_jinhua"] = "锁定技，每当你首次完成以下一项时，你增加1点体力上限，回复1点体力：<br>①对一名体力值≤0的角色使用【桃】<br>②于回合外不因“应援”获得手牌<br>③装备区内的牌数≥3。",
	["$v_jinhua"] = "",
}

--------------------------------------------------
--冰契
--技能马克：最佳时机为damageforseen，目前就用这俩时机；初步已写完，保险起见暂时隐藏本角色及本技能。
--技能描述：根据原Vup杀1.0.0.1版本，如果出现两个本技能持有者同场且全场（超过两人）均横置：
--①下家B攻击持有本技能的A，由A控制本次冰杀（其被视为伤害来源优先触发）
--②B攻击A以外任意角色，选择弃牌，铁索不解除，伤害不传导。
--②B攻击A以外任意角色，选择伤害，铁索解除，后续无论弃牌与否均传导。顺序为起始伤员-当前回合逆时针（从B开始算）
--------------------------------------------------

-- local v_bingqi = fk.CreateTriggerSkill{
--   --（刚需）技能认证名
--   name = "v_bingqi",
--   --(非必要）赋予特殊型技能定义
--   anim_type = "special",
--   --技能为锁定技，满足条件后强制发动
--   frequency = Skill.Compulsory,
--   --时机：受到伤害时，造成伤害前
--   -- events = {fk.DamageInflicted,fk.DamageCaused},
--   -- events = {fk.PreDamage},
--   events = {fk.DamageInflicted, fk.PreDamage},
--   --触发条件：
--   --（通用）触发时机的角色为遍历到的角色、遍历到的角色具有本技能、造成的伤害大于0，造成的伤害不为冰属性伤害。
--   --（受到伤害时）牌为实体牌、牌的种类为锦囊牌、造成的伤害大于0。
--   --（造成伤害时）造成伤害的来源为遍历到的角色、遍历到的角色具有本技能、牌为实体牌、牌的种类为锦囊牌、造成的伤害大于0。
--   can_trigger = function(self, event, target, player, data)
--     return target == player and player:hasSkill(self.name) 
--       and data.damage > 0 and data.damageType ~= fk.IceDamage
--   end,
--   on_use = function(self, event, target, player, data)
--     local room = player.room
--     data.damageType = fk.IceDamage
--     if data.to and data.to:hasSkill(self.name) then
--       data.from = data.to
--     end
--     room:sendLog{
--       type = "#v_bingqi_log",
--       from = data.from.id,
--       --log.to是数组
--       to = {data.to.id},
--       arg = self.name,
--       arg2 = data.damage,
--     }
--   end,
-- }

--------------------------------------------------
--灵窟
--FIXME:逃课解决了非基本牌的问题，但存在无法取消的问题，请期待新月杀新版本。
--------------------------------------------------

-- local v_lingku = fk.CreateActiveSkill{
--   name = "v_lingku",
--   anim_type = "special",
--   --使用条件：
--   -- 本回合只使用过一次技能；
--   -- （待补充）对方可以被技能指定为目标，技能可以对对方生效。
--   can_use = function(self, player)
--     return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
--   end,
--   target_num = 1,
--   card_filter = function(self, to_select, selected, selected_targets)
--     return false
--   end,
--   --目标选择：
--   -- 选定角色数量为0，选定角色不为自己，选定角色的手牌数>=3；
--   target_filter = function(self, to_select, selected)
--     local target = Fk:currentRoom():getPlayerById(to_select)
--     return #selected == 0 and to_select ~= Self.id and target:getHandcardNum() >= 3
--   end,
--   --on_use内可以先加一个skillnullify的判定用来配合偷梁换柱和精算等技能无效化的东西
--   -- （也希望这东西后续有更多优化吧）
--   on_use = function(self, room, effect)
--     --先随机选择对方三张手牌，根据是否为基本牌分门别类放好
--     local player = room:getPlayerById(effect.from)
--     local target = room:getPlayerById(effect.tos[1])
--     local ids = {}
--     local show_ids = {}
--     local can_choose_ids = {}
--     local cannot_choose_ids = {}
--     local hand = target:getCardIds(Player.Hand)
--     for _,cd in ipairs(hand) do
--       table.insert(ids, cd)
--     end
--     -- local foot_notes = {}
--     while #show_ids < 3 do
--       -- local ram = math.random(1, #ids)
--       -- local random_one = ids[ram]
--       local random_one = table.random(ids)
--       table.insert(show_ids, random_one)
--       -- table.remove(ids, ram + 1)
--       -- table.remove(ids, ram)
--       table.removeOne(ids, random_one)
--       -- table.insert(foot_notes, target.general.."+hand_area")
--       local ramcad = Fk:getCardById(random_one)
--       -- print(ramcad.type)
--       if ramcad.type == Card.TypeBasic then
--         table.insert(can_choose_ids, random_one)
--       else
--         table.insert(cannot_choose_ids, random_one)
--       end
--     end
--     --进入观看牌的环节
--     if #show_ids == 3 then
--       -- room:fillAG(player, show_ids, cannot_choose_ids)
--       room:fillAG(player, show_ids)
--       for _,p in ipairs(cannot_choose_ids) do
--         room:takeAG(target, p, room.players)
--         table.removeOne(show_ids, p)
--       end
--       local id1 = room:askForAG(player, show_ids, true, self.name)
--       -- local id1 = room:askForAG(player, can_choose_ids, true, self.name)
--       room:closeAG(player)
--       if id1 and id1 ~= -1 then
--         --展示牌
--         target:showCards(id1)
--         --摸牌（后续再做）
--         --记录牌堆的同名牌。
--         local can_get_ids = {}
--         --这里没摸到牌堆/弃牌堆的牌
--         local draw = room.draw_pile
--         for _,p in ipairs(draw) do
--           local card = Fk:getCardById(p)
--           local idcard = Fk:getCardById(id1)
--           if card.name == idcard.name then
--             table.insert(can_get_ids, p)
--           end
--         end
--         if #can_get_ids > 0 then
--           room:delay(500)
--           local card_id = table.random(can_get_ids)
--           -- local card_id = can_get_ids[math.random(1, #can_get_ids)]
--           room:obtainCard(target, Fk:getCardById(card_id), true, fk.ReasonPrey)
--         else
--           room:sendLog{
--             type = "#v_lingku_find_fail",
--             from = player.id,
--             arg = self.name,
--           }
--         end
--       end
--     end
--   end,
-- }

--------------------------------------------------
--牧野咲良
--角色马克：
-- 冰属性有待大量测试
--------------------------------------------------

-- local muyexiaoliang_dianyingdaiyuan = General(extension, "muyexiaoliang_dianyingdaiyuan", "individual", 3, 3, General.Female)
-- muyexiaoliang_dianyingdaiyuan:addSkill(v_bingqi)
-- muyexiaoliang_dianyingdaiyuan:addSkill(v_lingku)
-- muyexiaoliang_dianyingdaiyuan:addSkill(v_cheat)

-- Fk:loadTranslationTable{
-- 	["muyexiaoliang_dianyingdaiyuan"] = "牧野咲良",
-- 	["&muyexiaoliang_dianyingdaiyuan"] = "牧野咲良",
-- 	["#muyexiaoliang_dianyingdaiyuan"] = "点樱待缘",
-- 	["$muyexiaoliang_dianyingdaiyuan"] = "一般",
-- 	["designer:muyexiaoliang_dianyingdaiyuan"] = "NSX",
-- 	["cv:muyexiaoliang_dianyingdaiyuan"] = "",
-- 	["illustrator:muyexiaoliang_dianyingdaiyuan"] = "",
-- 	["~muyexiaoliang_dianyingdaiyuan"] = "",
-- 	["v_bingqi"] = "冰契",
-- 	[":v_bingqi"] = "锁定技，你造成/受到的伤害视为冰霜伤害，伤害来源视为你。",
-- 	["#v_bingqi_log"] = "由于“%arg”的效果，此伤害视为由 %from 对 %to 造成的 %arg2 点伤害[<b><font color='yellow'>冰属性</font></b>]",
-- 	["v_lingku"] = "灵窟",
-- 	[":v_lingku"] = "出牌阶段限一次，你可以指定一名其他角色<font color='#A9A9A9'>发动此技能</font>，你观看其<font color='#9400D3'>随机三张手牌</font>，然后你可以展示<font color='#9400D3'>其中</font>一张基本牌，其从牌堆随机获得一张与之牌名相同的牌。",
-- 	["$v_lingku"] = "",
-- 	["^v_lingku"] = "你可观看一名角色的三张牌，令其获得其中一张的同名牌<br/>操作提示：选择一名角色→确定",
-- 	["^AG_lingku"] = "<b>灵窟</b><br/>双击以选择一张牌展示，令目标从牌堆获得此牌的同名牌<br/>不选择请点击“确定”",
-- 	["#v_lingku_find_fail"] = "牌堆中没有 %from 可通过“%arg”获得的牌",
-- }

--------------------------------------------------
--棋圣
--TODO:魔法剑
--------------------------------------------------

local v_qisheng = fk.CreateActiveSkill{
  name = "v_qisheng",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name) == 0
  end,
  target_num = 0,
  min_card_num = 1,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player)
    if player:isAlive() then
      room:drawCards(player, #effect.cards, self.name)
      room:addPlayerMark(player, "@v_qisheng_card", #effect.cards)
      if player:getMark("@v_qisheng_card") >= 10 then
        room:broadcastSkillInvoke(self.name) --这个后续看效果 待定。
        --room:delay(2500)
        room:setPlayerMark(player, "@v_qisheng_card", 0)
        if not player:isKongcheng() then
          room:askForDiscard(player, 1, 1, false, self.name, false)
        end
        room:handleAddLoseSkills(player, "-v_qisheng|v_mogong_mfj|v_jiaojian_mfj", nil, true, false)
        --这里后续补获取魔法剑的方式
        for id = 0,500,1 do
          local card = Fk:getCardById(id)
          if card and card.name == "v_magicsword" then
            room:obtainCard(player, card, true)
          end
        end
      end
    end
  end
}

--------------------------------------------------
--魔法剑·魔攻
--------------------------------------------------

local v_mogong_mfj = fk.CreateTriggerSkill{
  name = "v_mogong_mfj",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and
      data.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否发动技能。
    local prompt = "v_mogong_mfj_choice"
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart",
    }
    room:judge(judge)
    if judge.card.suit == Card.Heart then
      room:obtainCard(player, judge.card, true)
      data.disresponsive = true
    end
  end,
}

--------------------------------------------------
--魔法剑·交剑
--------------------------------------------------

local v_jiaojian_mfj = fk.CreateTriggerSkill{
  name = "v_jiaojian_mfj",
  events = {fk.AskForCardUse, fk.AskForCardResponse},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and
      (data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none")))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否发动技能。
    local prompt = "v_jiaojian_mfj_choice"
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judgeData = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade",
    }
    room:judge(judgeData)

    if judgeData.card.suit == Card.Spade then
      room:obtainCard(player, judgeData.card, true)
      if event == fk.AskForCardUse then
        data.result = {
          from = player.id,
          card = Fk:cloneCard('jink'),
        }
        data.result.card.skillName = self.name

        if data.eventData then
          data.result.toCard = data.eventData.toCard
          data.result.responseToEvent = data.eventData.responseToEvent
        end
      else
        data.result = Fk:cloneCard('jink')
        data.result.skillName = self.name
      end

      return true
    end
  end
}

--------------------------------------------------
--水柳暮玥
--------------------------------------------------

local shuiliumuyue_benzhaimonv = General(extension, "shuiliumuyue_benzhaimonv", "individual", 4, 4, General.Agender)
shuiliumuyue_benzhaimonv:addSkill(v_qisheng)
shuiliumuyue_benzhaimonv:addRelatedSkill(v_mogong_mfj)
shuiliumuyue_benzhaimonv:addRelatedSkill(v_jiaojian_mfj)

Fk:loadTranslationTable{
	["shuiliumuyue_benzhaimonv"] = "水柳暮玥",
	["&shuiliumuyue_benzhaimonv"] = "水柳暮玥",
	["#shuiliumuyue_benzhaimonv"] = "笨宅魔女",
	["$shuiliumuyue_benzhaimonv"] = "一般",
	["designer:shuiliumuyue_benzhaimonv"] = "水柳暮玥",
	["cv:shuiliumuyue_benzhaimonv"] = "",
	["illustrator:shuiliumuyue_benzhaimonv"] = "",
	["~shuiliumuyue_benzhaimonv"] = "",
	["v_qisheng"] = "棋圣",
	["@v_qisheng_card"] = "棋圣蓄力中",
	[":v_qisheng"] = "出牌阶段限一次，你可以弃置任意张牌，摸等量张牌。若你以此法获得过至少10张牌，你弃置一张手牌，失去“棋圣”，获得“魔法剑·魔攻”、“魔法剑·交剑”和一张【魔法剑】。",
	["$v_qisheng"] = "",
	["v_mogong_mfj"] = "魔法剑·魔攻",
	[":v_mogong_mfj"] = "<font color='#008B8B'><b>衍生技，</b></font>你使用【杀】指定目标后，你可以<font color='#A9A9A9'>发动此技能</font>，进行一次判定，若结果为红桃，你获得判定牌，此【杀】不能被【闪】响应。",
	["$v_mogong_mfj"] = "",
	["v_mogong_mfj_choice"] = "你可以发动“魔法剑·魔攻”，判定红桃则此【杀】不可闪避",
	["v_jiaojian_mfj"] = "魔法剑·交剑",
	[":v_jiaojian_mfj"] = "<font color='#008B8B'><b>衍生技，</b></font>你需要使用或打出【闪】时，你可以<font color='#A9A9A9'>发动此技能</font>，进行一次判定，若结果为黑桃，你获得判定牌，视为使用或打出一张【闪】。",
	["$v_jiaojian_mfj"] = "",
	["v_jiaojian_mfj_choice"] = "你可以发动“魔法剑·交剑”，判定黑桃则视为出【闪】",
}

--------------------------------------------------
--娴静
--------------------------------------------------

local v_xianjing = fk.CreateTriggerSkill{
  name = "v_xianjing",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  --触发条件：
  -- 遍历到的角色持有该技能；
  -- 触发时机的角色处于准备阶段;
  -- 触发时机的角色判定区中存在牌。
  -- （待补充）技能没有被无效；遍历到的角色的技能可以对触发时机的角色产生影响。
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and
      target.phase == Player.Start and
      #target:getCardIds(Player.Judge) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否发动技能。
    local prompt = "v_xianjing_choice:"..target.id
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    if player.id ~= target.id then
      room:doIndicate( player.id, {target.id} )
    end
    target:turnOver()
    --测试用，放到牌堆顶
    -- room:moveCardTo(target:getCardIds(Player.Judge), Card.DrawPile, nil, fk.ReasonJustMove, self.name, nil, true)
    -- local ram = math.random(1, #room.draw_pile + 1)
    -- room:moveCards({
    --   ids = target:getCardIds(Player.Judge),
    --   from = target.id,
    --   toArea = Card.DrawPile,
    --   moveReason = fk.ReasonJustMove,
    --   skillName = self.name,
    --   drawPilePosition = ram,
    -- })
    VslUtil.return_draw_pile(target, target:getCardIds(Player.Judge), self.name)
    room:delay(250)
  -- end
  end
}

--------------------------------------------------
--儒琴
--TODO：后续可以关注一下儒琴和奇遇的配合方式，后续处理；可能需要涉及所有伤害计算方式的修改。
-- 目前倾向于最多额外出牌阶段相比于原版可以多开一次儒琴
-- 但额外回合使用的儒琴应该不会影响到自己的正常回合。
--------------------------------------------------

local v_ruqin = fk.CreateTriggerSkill{
  name = "v_ruqin",
  --赋予进攻型技能定义
  anim_type = "offensive",
  --时机：阶段结束时
  events = {fk.EventPhaseEnd},
  --触发条件：
  --（阶段结束时）触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  --              被遍历到的角色处于出牌阶段。
  --              被遍历到的角色本回合未造成伤害，被遍历到的角色存在出牌阶段
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
    and player.phase == Player.Play
    and player:getMark("#turn_damage-turn") == 0 and VslUtil.exist_or_not(player, Player.Play) 
  end,
  on_cost = function(self, event, target, player, data)
    --确认是否发动技能。
    local room = player.room
    local targets = {}
    local others = room:getOtherPlayers(player, true, false)
    local prompt = "v_ruqin_ask"
    for _,p in ipairs(others) do
      local pm = p:getMark("#target_specified-turn")
      local mycr = false
      if pm ~= 0 then
        for _,t in ipairs(pm) do
          if t == player.id then
            mycr = true
            break
          end
        end
      end
      if mycr then
        --后续可以在这里补充以下判定：
        -- 遍历到的角色可以选定目标使用本技能且技能可以对目标生效。
        table.insert(targets, p.id)
      end
    end
    local ret = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
    --确认是否发动技能。
    if #ret > 0 then
      --后续可以在这里补充以下判定：
      -- 遍历到的角色本技能未被元初之类的。
      self.cost_data = ret[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    tar:drawCards(1, self.name)
    room:damage{
      from = player,
      to = tar,
      damage = 1,
      skillName = self.name,
    }
  end,
}

--------------------------------------------------
--梦音茶糯
--------------------------------------------------

local mengyinchanuo_xiuwaihuizhong = General(extension, "mengyinchanuo_xiuwaihuizhong", "individual", 3, 3, General.Female)
mengyinchanuo_xiuwaihuizhong:addSkill(v_xianjing)
mengyinchanuo_xiuwaihuizhong:addSkill(v_ruqin)

Fk:loadTranslationTable{
	["mengyinchanuo_xiuwaihuizhong"] = "梦音茶糯",
	["&mengyinchanuo_xiuwaihuizhong"] = "梦音茶糯",
	["#mengyinchanuo_xiuwaihuizhong"] = "秀外慧中",
	["$mengyinchanuo_xiuwaihuizhong"] = "简单",
	["designer:mengyinchanuo_xiuwaihuizhong"] = "NSX",
	["cv:mengyinchanuo_xiuwaihuizhong"] = "",
	["illustrator:mengyinchanuo_xiuwaihuizhong"] = "",
	["~mengyinchanuo_xiuwaihuizhong"] = "",
	["v_xianjing"] = "娴静",
	[":v_xianjing"] = "一名角色的准备阶段，若其判定区内有牌，你可以<font color='#A9A9A9'>发动此技能</font>，令其翻面，将其判定区内的牌返回牌堆。",
	["$v_xianjing"] = "",
	["v_xianjing_choice"] = "你可以发动“娴静”，令 %src 翻面，然后将其判定区内的牌返回牌堆",
	["v_ruqin"] = "儒琴",
	[":v_ruqin"] = "出牌阶段结束时，若你于本回合内未造成过伤害且<font color='#9400D3'>使用牌指定过其他角色</font>，你可以指定<font color='#9400D3'>其中一名角色</font>，<font color='#A9A9A9'>发动此技能</font>，其摸一张牌，然后你对其造成1点伤害。",
	["$v_ruqin"] = "",
	["v_ruqin_ask"] = "你可以发动“儒琴”，令一名角色摸一张牌，然后对其造成1点伤害",
}

--------------------------------------------------
--紫禁
--------------------------------------------------

local v_zijin = fk.CreateTriggerSkill{
  name = "v_zijin",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  --触发条件：
  -- 触发时机的角色为遍历到的角色，遍历到的角色持有该技能；
  -- 触发时机的角色处于结束阶段;
  -- 触发时机的角色本回合未造成伤害；
  -- 触发时机的角色有牌。
  -- （待补充）技能没有被无效；遍历到的角色的技能可以对触发时机的角色产生影响。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
      and player.phase == Player.Finish
      and player:getMark("#turn_damage-turn") == 0
      and (not player:isNude())
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    local others = room:getOtherPlayers(player, true, false)
    local prompt = "v_zijin_ask"
    for _,p in ipairs(others) do
      --后续可以在这里补充以下判定：
      -- 遍历到的角色可以选定目标使用本技能且技能可以生效，目标可以弃置遍历到的角色的牌。
      table.insert(targets, p.id)
    end
    local ret = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
    --确认是否发动技能。
    if #ret > 0 then
      --后续可以在这里补充以下判定：
      -- 遍历到的角色本技能未被元初之类的无效，目标可以弃置遍历到的角色的牌。
      self.cost_data = ret[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = room:getPlayerById(self.cost_data)
    local throw_id = room:askForCardChosen(targets, player, "he", self.name)
    room:throwCard(throw_id, self.name, player, targets)
    local car = Fk:getCardById(throw_id)
    if car.type == Card.TypeBasic then
      room:setTag("RoundCount", room:getTag("RoundCount") + 2)
      local pls = room.players
      --为全体玩家更新轮数
      for _,p in ipairs(pls) do
        p:doNotify("UpdateRoundNum", room:getTag("RoundCount") or 0)
      end
      room:sendLog{
        type = "#v_zijin_addround",
        arg = self.name,
        arg2 = room:getTag("RoundCount"),
      }
    else
      room:damage{
        from = player,
        to = targets,
        damage = 1,
        skillName = self.name,
      }
    end
  -- end
  end
}

--------------------------------------------------
--本怖
--------------------------------------------------

local v_benbu = fk.CreateTriggerSkill{
  name = "v_benbu",
  frequency = Skill.Wake,
  anim_type = "support",
  events = {fk.RoundStart},
  --触发条件：
  -- 遍历到的角色持有该技能；
  -- 遍历到的角色未使用过该技能
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  --觉醒条件：进行一次判定，结果点数<=游戏轮数则觉醒
  can_wake = function(self, event, target, player, data)
    local room = player.room
    local pattern = ".|1~" .. room:getTag("RoundCount")
    local judge = {
      who = player,
      reason = self.name,
      pattern = pattern,
    }
    room:judge(judge)
    local num = judge.card.number
    return num <= room:getTag("RoundCount")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --后续这里可以补充动画和配音，以及角色图片&称号的变化。
    --回复一点体力并获得技能。
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    room:handleAddLoseSkills(player, "v_chushou", nil)
  end,
}

--------------------------------------------------
--触手
--------------------------------------------------

local v_chushou_buff = fk.CreateMaxCardsSkill{
  name = "#v_chushou_buff",
  correct_func = function(self, player)
    if player:getMark("@v_chushou") > 0 then
      return -player:getMark("@v_chushou")
    end
  end,
}
local v_chushou = fk.CreateTriggerSkill{
  name = "v_chushou",
  --赋予控场型技能定义
  anim_type = "control",
  frequency = Skill.Compulsory,
  --时机：受到伤害后
  events = {fk.Damaged},
  --触发条件：（这部分没写完）
  -- 触发时机的角色为遍历到的角色；遍历到的角色具有本技能；
  -- 伤害大于0，存在伤害源
  -- 伤害源不为遍历到的角色
  -- （待补充）技能可以对对方生效。
  can_trigger = function(self, event, target, player, data)
    local damage = data
    return target == player and player:hasSkill(self.name) 
    and damage.damage > 0 
    and damage.from and damage.from:isAlive()
    and damage.from ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- if player.id ~= data.from.id then
    room:doIndicate( player.id, {data.from.id} )
    -- end
    room:delay(250)
    room:addPlayerMark(data.from, "@v_chushou", 1)
    room:addPlayerMark(player, "@v_chushou", 1)
    room:damage{
      from = player,
      to = data.from,
      damage = 1,
      skillName = self.name,
    }
  end,
}

v_chushou:addRelatedSkill(v_chushou_buff)

--------------------------------------------------
--夏卜卜
--------------------------------------------------

local xiabubu_zhixingjiejie = General(extension, "xiabubu_zhixingjiejie", "individual", 4, 4, General.Agender)
xiabubu_zhixingjiejie:addSkill(v_zijin)
xiabubu_zhixingjiejie:addSkill(v_benbu)
xiabubu_zhixingjiejie:addRelatedSkill(v_chushou)

Fk:loadTranslationTable{
	["xiabubu_zhixingjiejie"] = "夏卜卜",
	["&xiabubu_zhixingjiejie"] = "夏卜卜",
	["#xiabubu_zhixingjiejie"] = "知性姐姐",
	["$xiabubu_zhixingjiejie"] = "一般",
	["designer:xiabubu_zhixingjiejie"] = "NSX、月音风源",
	["cv:xiabubu_zhixingjiejie"] = "",
	["illustrator:xiabubu_zhixingjiejie"] = "",
	["~xiabubu_zhixingjiejie"] = "",
	["v_zijin"] = "紫禁",
	[":v_zijin"] = "结束阶段，若你本回合未造成过伤害，你可以指定一名其他角色，<font color='#A9A9A9'>发动此技能</font>，令其破坏你一张牌，若之为基本牌则游戏轮数＋2，否则你对其造成1点伤害。",
	["$v_zijin"] = "",
	["v_zijin_ask"] = "你可以发动“紫禁”，指定一名其他角色，其破坏你一张牌，若之不为基本牌则对其造成1点伤害",
	["#v_zijin_addround"] = "由于“%arg”的效果，游戏轮数增加至第 %arg2 轮",
	["v_benbu"] = "本怖",
	[":v_benbu"] = "觉醒技，<font color='#4B0082'><b>变身技，</b></font>轮次开始时，进行一次判定，若结果点数≤游戏轮数，你回复1点体力，获得“触手”。",
	["$v_benbu"] = "（变身音效）",
	["v_chushou"] = "触手",
	["@v_chushou"] = "触手",
	["v_chushou_buff"] = "触手",
	[":v_chushou"] = "锁定技，你受到伤害后，对伤害来源造成1点伤害，你与其手牌上限－1。",
	["$v_chushou"] = "",
}

--------------------------------------------------
--神伴
--技能马克:后续可以补充光神的图片
--技能马克2：原Vup V1.0.1版本中技能指定顺序为ABCABC
--      但根据FK主创团队的说法，这里排序规则应该是AABBCC
--      如需维持原有规律，请参考“丰姿”
--------------------------------------------------

local v_shenban = fk.CreateActiveSkill{
  name = "v_shenban",
  anim_type = "support",
  can_use = function(self, player)
    return (not player:isNude())
  end,
  target_num = 1,
  card_num = 1,
  --可以弃置此牌，此牌颜色为红色。
  card_filter = function(self, to_select, selected, selected_targets)
    if #selected == 1 then return false end
    local card = Fk:getCardById(to_select)
    return card.color == Card.Red and (not Self:prohibitDiscard(card))
  end,
  --（待补充）技能可以指定其为目标，你可以令此技能对其生效
  target_filter = function(self, to_select, selected)
    -- local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0
  end,
  --后续可以在这里补充元初类判定
  on_use = function(self, room, effect)
    --先拼点
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, player)
    room:addPlayerMark(target, "@v_shenban", 1)
    if player.phase == Player.Play then
      player.room.logic:getCurrentEvent():findParent(GameEvent.Phase):shutdown()
    end
  end,
}
local v_shenban_tar = fk.CreateTriggerSkill{
  name = "#v_shenban_tar",
  --赋予输出型技能定义,
  anim_type = "offensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.TargetSpecified},
  --触发条件：
  --             触发时机的角色为遍历到的角色，遍历到的角色存在神伴标记
  --             触发的牌真名为杀或为普通锦囊牌，触发的牌为实体牌
  --             本次流程中第一次触发这个时机（待定）
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@v_shenban") > 0
    and (data.card.trueName == "slash" or (data.card.type == Card.TypeTrick and
    data.card.sub_type ~= Card.SubtypeDelayedTrick)) and data.card.id > 0
    and data.firstTarget
  end,
  --关于data.targetGroup和data.tos的区别后续可以用dbg处理
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@v_shenban", 1)
    room:setEmotion(player, "./packages/vupslash/image/anim/v_shenban")
    local tarold = AimGroup:getAllTargets(data.tos)
    local tarnew = {}
    for _, p in ipairs(tarold) do
      TargetGroup:pushTargets(data.targetGroup, p)
      table.insert(tarnew, p)
      table.insert(tarnew, p)
    end
    --注释：发log用的to是一维数组，而tos是二维数组
    room:sendLog{
      type = "#v_shenban_log",
      from = player.id,
      to = tarnew,
      arg = self.name,
      card = { data.card.id },
    }
  end,
}

--由于世界名画“五谷丰登和无懈可击”，这玩意还需要完善下再拿出去···
-- local v_shenban_tar = fk.CreateTriggerSkill{
--   name = "#v_shenban_tar",
--   --赋予输出型技能定义,
--   anim_type = "offensive",
--   --技能为锁定技，满足条件后强制发动
--   frequency = Skill.Compulsory,
--   events = {fk.AfterCardTargetDeclared},
--   --使用条件：
--   --             触发时机的角色为遍历到的角色，遍历到的角色存在神伴标记
--   --             触发的牌真名为杀或为普通锦囊牌，触发的牌为实体牌
--   can_trigger = function(self, event, target, player, data)
--     return target == player and player:getMark("@v_shenban") > 0
--     and (data.card.trueName == "slash" or (data.card.type == Card.TypeTrick and
--     data.card.sub_type ~= Card.SubtypeDelayedTrick)) and data.card.id > 0
--   end,
--   -- on_cost = function(self, event, target, player, data)
--   --   local type = data.card:getTypeString()
--   --   return #player.room:askForDiscard(player, 1, 1, false, self.name, true, ".|.|.|.|.|"..type,
--   --     "#fengzi-invoke:::"..type..":"..data.card:toLogString()) > 0
--   -- end,
--   on_use = function(self, event, target, player, data)
--     local room = player.room
--     room:removePlayerMark(player, "@v_shenban", 1)
--     room:setPlayerMark(player, self.name, TargetGroup:getRealTargets(data.tos))
--   end,

--   refresh_events = {fk.CardUseFinished},
--   can_refresh = function(self, event, target, player, data)
--     return target == player and player:hasSkill(self.name, true) and player:getMark(self.name) ~= 0
--   end,
--   on_refresh = function(self, event, target, player, data)
--     local room = player.room
--     room:setEmotion(player, "./packages/vupslash/image/anim/v_shenban")
--     local targets = player:getMark(self.name)
--     room:setPlayerMark(player, self.name, 0)
--     for _, id in ipairs(targets) do
--       if room:getPlayerById(id).dead then
--         table.removeOne(targets, id)
--       end
--     end
--     if #targets > 0 then
--       --注释：发log用的to是一维数组，而tos是二维数组
--       room:sendLog{
--         type = "#v_shenban_log",
--         from = player.id,
--         -- to = targets,
--         arg = self.name,
--         card = { data.card.id },
--       }
--       --这牌要不要把原牌带的技能带上后续再说。
--       room:useVirtualCard(data.card.name, nil, player, table.map(targets, function(id) return room:getPlayerById(id) end), self.name, true)
--     end
--   end,
-- }

v_shenban:addRelatedSkill(v_shenban_tar)

--------------------------------------------------
--逝随
--------------------------------------------------

local v_shisui = fk.CreateTriggerSkill{
  name = "v_shisui",
  anim_type = "support",
  events = {fk.EnterDying},
  --使用条件：
  --  遍历到的角色具有本技能
  --  触发时机的角色存在且不为遍历到的角色，触发时机的角色体力小于1
  --  （待补充）not skillnullify，player:caneffect
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) 
    and target and target ~= player and target.hp <1 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForSkillInvoke(player, self.name, data)
    return choice
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target ~= player then
      --doindicate的两个参数一个为integer，一个为table
      room:doIndicate(player.id, { target.id })
    end
    --降低一点体力上限，回复对方一点体力。
    room:changeMaxHp(player, -1)
    room:recover{
      who = target,
      num = 1,
      recoverBy = player,
      skillName = self.name,
    }
    -- room:setPlayerMark(target, "v_shisui_alive", 1)
    -- data.extra_data.shisui = target.id
    -- 如果以下条件存在，触发后续机制：
    --  触发时机的角色存在且存活，触发时机的角色存在牌
    if (target or {}):isAlive() and not target:isAllNude() then
      local ids = {}
      local ids_loc = {}
      local take_ids = {}
      -- local show_ids = {}
      -- local can_choose_ids = {}
      local cannot_choose_ids = {}
      local hand = target:getCardIds(Player.Hand)
      local equip = target:getCardIds(Player.Equip)
      local judge = target:getCardIds(Player.Judge)
      for _,cd in ipairs(hand) do
        table.insert(ids, cd)
        table.insert(ids_loc, {cd, hand})
      end
      for _,cd in ipairs(equip) do
        table.insert(ids, cd)
        table.insert(ids_loc, {cd, equip})
      end
      for _,cd in ipairs(judge) do
        table.insert(ids, cd)
        table.insert(ids_loc, {cd, judge})
      end
      --进入拿牌环节
      while #ids ~= #cannot_choose_ids do
        -- room:fillAG(player, show_ids, cannot_choose_ids)
        room:fillAG(player, ids)
        for _,p in ipairs(cannot_choose_ids) do
          room:takeAG(target, p, room.players)
          -- table.removeOne(ids, p)
        end
        local id1 = room:askForAG(player, ids, false, self.name)
        -- local id1 = room:askForAG(player, can_choose_ids, true, self.name)
        if id1 and id1 ~= -1 then
          room:closeAG(player)
          -- dummy:addSubcard(id1)
          local card1 = Fk:getCardById(id1)
          table.insert(take_ids, id1)
          for _,cd in ipairs(ids_loc) do
            local car = Fk:getCardById(cd[1])
            if car == card1 then
              for _,cd in ipairs(cd[2]) do
                table.insert(cannot_choose_ids, cd)
              end
            end
          end
        end
      end
      if #take_ids > 0 then
        room:moveCards({
          ids = take_ids,
          from = target.id,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
        })
        -- room.obtainCard(player, dummy, false, fk.ReasonPrey)  --等会用movecard试试
      end
    end
    -- elseif event == fk.AfterDying then
    --   return true
    -- end
  end,
}

-- 本版本暂时废弃
-- local v_shisui = fk.CreateTriggerSkill{
--   name = "v_shisui",
--   anim_type = "support",
--   events = {fk.EnterDying, fk.AfterDying},
--   --使用条件：
--   -- 进入濒危状态:
--   --  遍历到的角色具有本技能
--   --  触发时机的角色存在且不为遍历到的角色，触发时机的角色体力小于1
--   --  （待补充）not skillnullify，player:caneffect
--   -- 脱离濒危状态:
--   --  遍历到的角色具有本技能（为了防止插结失去技能，可以删掉）
--   -- 触发时机的角色存在且存活，触发时机的角色存在牌，触发时机的角色存在标记（待定）
--   -- 注释：这个标记需要在玩家死亡后可以自动被清理掉的能力，先按照会被清洗掉交给触发时机的角色。
--   can_trigger = function(self, event, target, player, data)
--     if event == fk.EnterDying then
--       return player:hasSkill(self.name) 
--       and target and target ~= player and target.hp <1 
--     elseif event == fk.AfterDying then
--       return player:hasSkill(self.name) 
--         and (target or {}):isAlive() and not target:isAllNude() 
--         and data.extra_data.shisui == target.id
--     end
--   end,
--   on_cost = function(self, event, target, player, data)
--     if event == fk.EnterDying then
--       local room = player.room
--       local choice = room:askForSkillInvoke(player, self.name, data)
--       return choice
--     elseif event == fk.AfterDying then
--       return true
--     end
--   end,
--   on_use = function(self, event, target, player, data)
--     local room = player.room
--     if event == fk.EnterDying then
--       if target ~= player then
--         --doindicate的两个参数一个为integer，一个为table
--         room:doIndicate(player.id, { target.id })
--       end
--       --降低一点体力上限，回复对方一点体力。
--       room:changeMaxHp(player, -1)
--       room:recover{
--         who = target,
--         num = 1,
--         recoverBy = player,
--         skillName = self.name,
--       }
--       -- room:setPlayerMark(target, "v_shisui_alive", 1)
--       data.extra_data.shisui = target.id
--     elseif event == fk.AfterDying then
--       return true
--     end
--   end,
-- }

--------------------------------------------------
--绫濑光
--------------------------------------------------

local linglaiguang_shengsixiangyi = General(extension, "linglaiguang_shengsixiangyi", "individual", 4, 4, General.Agender)
linglaiguang_shengsixiangyi:addSkill(v_shenban)
linglaiguang_shengsixiangyi:addSkill(v_shisui)
-- linglaiguang_shengsixiangyi:addSkill(v_lose)
-- linglaiguang_shengsixiangyi:addSkill(v_cheat)

Fk:loadTranslationTable{
	["linglaiguang_shengsixiangyi"] = "绫濑光",
	["&linglaiguang_shengsixiangyi"] = "绫濑光",
	["#linglaiguang_shengsixiangyi"] = "生死相依",
	["$linglaiguang_shengsixiangyi"] = "一般",
	["designer:linglaiguang_shengsixiangyi"] = "月音风源",
	["cv:linglaiguang_shengsixiangyi"] = "",
	["illustrator:linglaiguang_shengsixiangyi"] = "",
	["~linglaiguang_shengsixiangyi"] = "",
	["v_shenban"] = "神伴",
	["#v_shenban_tar"] = "神伴",
	["@v_shenban"] = "神伴",
	--注释：现版本中绫濑光神伴卡诺娅，卡诺娅的技能本身不会二次发动。
	[":v_shenban"] = "出牌阶段，你可以弃置一张红色牌并指定一名角色，结束本阶段，令其下次使用的非转化的【杀】或普通锦囊牌额外指定每个目标各一次。",
	-- [":v_shenban"] = "出牌阶段，你可以弃置一张红色牌并指定一名角色，结束本阶段，令其下次使用的非转化的【杀】或普通锦囊牌额外指定目标一次。",
	-- [":v_shenban"] = "出牌阶段，你可以弃置一张红色牌并指定一名角色，<font color='#A9A9A9'>发动此技能</font>，结束本阶段，令其下次使用的非转化的【杀】或普通锦囊牌额外结算一次。",
	["$v_shenban"] = "",
	["^v_shenban"] = "操作提示：<br/>选择一张红色牌→选择一名角色→确定",
	["#v_shenban_log"] = "由于“%arg”的效果，%from 使用的 %card 目标改为 %to",
	-- ["#v_shenban_log"] = "由于“%arg”的效果，%from 使用的 %card 额外结算一次",
	[":mark:&v_shenban"] = "你使用的下一张【杀】或普通锦囊牌将生效两次",
	["v_shisui"] = "逝随",
	[":v_shisui"] = "一名其他角色进入濒危状态时，你可以<font color='#A9A9A9'>发动此技能</font>，失去1点体力上限，令其回复1点体力，然后你观看其手牌并获得其每个区域内的各一张牌。",
	["$v_shisui"] = "",
	["^AG_v_shixui"] = "<b>逝随</b><br/>依次双击选择每个区域内的各一张牌获得",
}

--------------------------------------------------
--血林
--------------------------------------------------

local v_xuelin = fk.CreateTriggerSkill{
  name = "v_xuelin",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) 
    and data.from and not data.from.dead
      and data.damage > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    if from and player ~= from then room:doIndicate(player.id, {from.id}) end
    local judge = {
      who = from,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if judge.card.color == Card.Red then
      room:damage{
        from = player,
        to = from,
        damage = 1,
        skillName = self.name,
      }
    elseif judge.card.color == Card.Black then
      room:askForDiscard(from, 2, 2, true, self.name, false)
    end
  end,
}

--------------------------------------------------
--寻腥
--------------------------------------------------

local v_xunxing = fk.CreateTriggerSkill{
  name = "v_xunxing",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  --使用条件：（已完成）
  -- 伤害>0，存在源与目标；
  -- 遍历到的角色在源的攻击范围内，目标为触发时机的角色，触发时机的角色不为遍历到的角色；
  -- 遍历到的角色区域内有牌，遍历到的角色具有本技能。
  can_trigger = function(self, event, target, player, data)
    return data.damage > 0 
    --  and data.from and data.to
     and (data.from or {}):inMyAttackRange(player) and (data.to or {}) == target and target ~= player
     and not player:isNude() and player:hasSkill(self.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "v_xunxing_ask:"..target.id
    local card = room:askForCard(player, 1, 1, true, self.name, true, ".", prompt)[1]
    if card then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(self.cost_data)
    room:moveCardTo(card, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, false)
    room:damage{
      from = data.from,
      to = player,
      damage = data.damage,
      damageType = data.type,
      skillName = self.name,
    }
    return true
  end,
}

--------------------------------------------------
--奈奈莉娅
--------------------------------------------------

local nainailiya_yuanbenlinyuan = General(extension, "nainailiya_yuanbenlinyuan", "individual", 4, 4, General.Female)
nainailiya_yuanbenlinyuan:addSkill(v_xuelin)
nainailiya_yuanbenlinyuan:addSkill(v_xunxing)

Fk:loadTranslationTable{
	["nainailiya_yuanbenlinyuan"] = "奈奈莉娅",
	["&nainailiya_yuanbenlinyuan"] = "奈奈莉娅",
	["#nainailiya_yuanbenlinyuan"] = "缘本临渊",
	["designer:nainailiya_yuanbenlinyuan"] = "NSX",
	["cv:nainailiya_yuanbenlinyuan"] = "",
	["illustrator:nainailiya_yuanbenlinyuan"] = "",
	["~nainailiya_yuanbenlinyuan"] = "",
	["v_xuelin"] = "血林",
	[":v_xuelin"] = "你受到伤害后，你可以<font color='#A9A9A9'>发动此技能</font>，令伤害来源进行一次判定，若结果为：红色，你对其造成1点伤害；黑色，其须弃置两张牌。",
	["$v_xuelin"] = "",
	--["v_xuelin:choice"] = "你可以对 %src 发动“血林”",
	["v_xunxing"] = "寻腥",
	[":v_xunxing"] = "一名其他角色受到伤害时，若你在伤害来源的攻击范围内，你可以<font color='#A9A9A9'>发动此技能</font>，将一张牌置于牌堆顶，然后将此伤害转移给你。",
	["$v_xunxing"] = "",
	--["v_xunxing:choice"] = "你可以发动“寻腥”，代替 %src 承受此伤害",
	["v_xunxing_ask"] = "你可以发动“寻腥”，将一张牌置于牌堆顶，代替 %src 承受此伤害",
}

--------------------------------------------------
--炽翎
--TODO:如果在展示牌之后出现因为其他技能导致的弃置需要思考方案
--------------------------------------------------

local v_chiling = fk.CreateViewAsSkill{
  name = "v_chiling",
  anim_type = "offensive",
  pattern = "fire_attack",
  card_filter = function(self, to_select, selected)
    local card = Fk:getCardById(to_select)
    return #selected == 0 and card.color == Card.Red
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("fire_attack")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
}
local v_chiling_next = fk.CreateTriggerSkill{
  name = "#v_chiling_next",
  anim_type = "offensive",
  mute = true,
  --时机：卡牌使用宣告后，卡牌移动后，伤害造成时
  events = {fk.AfterCardUseDeclared, fk.AfterCardsMove, fk.DamageCaused},
  --使用条件：
  -- 卡牌使用宣告后：触发时机的角色为遍历到的角色，遍历到的角色存在此技能
  --                遍历到的角色存在手牌，牌名为火攻，
  --                牌的技能名为v_chiling；
  -- 卡牌移动后：遍历到的角色存在此技能
  --            存在特定mark，弃牌skillname为火攻，弃牌原因为弃置【如果不对，后续用dbg查】；
  -- 伤害造成时：触发时机的角色为遍历到的角色，遍历到的角色存在此技能
  --             伤害>0，造成伤害的牌为火攻，
  --             造成伤害的牌的技能名为v_chiling，存在特定mark。
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      return target == player and player:hasSkill(self.name) 
        and (not player:isKongcheng()) and data.card and data.card.name == "fire_attack"
        and data.card.skillName == "v_chiling"
        -- and table.contains(data.card.skillNames, "v_chiling")
    elseif event == fk.AfterCardsMove then
      local room = player.room
      local move = data
      --后续discardpile可能删掉
      if player:hasSkill(self.name) and (not (player:getMark("v_chiling_id") > 0) and move.skillName == "fire_attack"
      and move.from == player.id 
      and move.toArea == Card.DiscardPile
      ) then
        return false
      end
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand 
            and (room:getCardArea(info.cardId) == Card.DiscardPile or room:getCardArea(info.cardId) == Card.Processing)
            and info.cardId == player:getMark("v_chiling_id") then
            return true
          end
        end
      end
    elseif event == fk.DamageCaused then
      return target == player and player:hasSkill(self.name) 
        and data.damage > 0 and data.card and data.card.name == "fire_attack" 
        and data.card and data.card.skillName == "v_chiling" and player:getMark("v_chiling_damage") > 0
        -- and data.card and table.contains(data.card.skillNames, "v_chiling") and player:getMark("v_chiling_damage") > 0
      end
  end,
  --使用条件：
  -- 卡牌使用宣告后：需要askforcard（仅限手牌），存在且非虚拟牌则return true；
  -- 其他：return true
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardUseDeclared then
      local prompt = "v_chiling_card"
      local card = room:askForCard(player, 1, 1, false, self.name, true, ".", prompt)[1]
      if card and card > 0 then
        self.cost_data = card
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardUseDeclared then
      room:sendLog{
        type = "#v_chiling_selected_log",
        from = player.id,
        arg = self.name,
        arg2 = 1,
      }
      local cid = self.cost_data
      room:setPlayerMark(player, "v_chiling_id", cid)
      local hand = player:getCardIds(Player.Hand)
      local hands = {}
      for _,p in ipairs(hand) do
        if p ~= cid then
          table.insert(hands, p)
        end
      end
      if #hands > 0 then
        player:showCards(hands)
        room:delay(500)
      end
    elseif event == fk.AfterCardsMove then
      room:setPlayerMark(player, "v_chiling_id", 0)
      room:setPlayerMark(player, "v_chiling_damage", 1)
    elseif event == fk.DamageCaused then
      data.damage = data.damage + 1
      room:setPlayerMark(player, "v_chiling_id", 0)
      room:setPlayerMark(player, "v_chiling_damage", 0)
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
      and (player:getMark("v_chiling_id") > 0 or player:getMark("v_chiling_damage") > 0)
      and (data.card or {}).name == "fire_attack"
      and (data.card or {}).skillName == "v_chiling"
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "v_chiling_id", 0)
    room:setPlayerMark(player, "v_chiling_damage", 0)
  end,
}
v_chiling:addRelatedSkill(v_chiling_next)

--------------------------------------------------
--离息
--------------------------------------------------

local v_lixi = fk.CreateTriggerSkill{
  name = "v_lixi",
  anim_type = "support",
  -- mute = true,
  -- 这是最接近离场的时机···
  events = {fk.AskForPeachesDone},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name)) then return false end
    local room = player.room
    local draw = room.draw_pile
    for _,p in ipairs(draw) do
    local card = Fk:getCardById(p)
      -- print(card.name)
      if card.name == "fan" then
        return true
      end
    end
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    return true
  end,
}

--------------------------------------------------
--秋乌
--------------------------------------------------

local qiuwu_chiwuliuhuo = General(extension, "qiuwu_chiwuliuhuo", "individual", 3, 3, General.Bigender)
qiuwu_chiwuliuhuo:addSkill(v_chiling)
qiuwu_chiwuliuhuo:addSkill(v_lixi)

Fk:loadTranslationTable{
	["qiuwu_chiwuliuhuo"] = "秋乌",
	["&qiuwu_chiwuliuhuo"] = "秋乌",
	["#qiuwu_chiwuliuhuo"] = "赤乌流火",
	["$qiuwu_chiwuliuhuo"] = "一般",
	["designer:qiuwu_chiwuliuhuo"] = "NSX",
	["cv:qiuwu_chiwuliuhuo"] = "",
	["illustrator:qiuwu_chiwuliuhuo"] = "",
	["~qiuwu_chiwuliuhuo"] = "",
	["v_chiling"] = "炽翎",
	["#v_chiling_next"] = "炽翎",
	[":v_chiling"] = "出牌阶段限一次，你可以将一张红色牌当【火攻】使用，然后你可以<font color='#9400D3'>选择一张手牌</font>并展示其余手牌，你因此【火攻】弃置<font color='#9400D3'>所选的牌</font>并造成伤害时，此伤害＋1。",
	["$v_chiling"] = "",
	["v_chiling_ask"] = "你可以选择一张手牌，展示其余手牌，若本次火攻弃置了所选的牌，则造成的伤害+1",
	["v_chiling_card"] = "你可以选择一张手牌，展示其余手牌，若本次火攻弃置了所选的牌，则造成的伤害+1<br/>操作提示：选择一张手牌→确定",
	["#v_chiling_selected_log"] = "%from 执行了“%arg”的效果，选择了 %arg2 张手牌",
	["v_lixi"] = "离息",
	[":v_lixi"] = "锁定技，牌堆中有【朱雀羽扇】时，你不会因体力值减少而离场。",
	["$v_lixi"] = "",
}

--------------------------------------------------
--渴欲
--------------------------------------------------

local v_keyu = fk.CreateTriggerSkill{
  name = "v_keyu",
  --赋予防御型技能定义
  anim_type = "defensive",
  --时机：体力回复后
  events = {fk.HpRecover},
  --使用条件：
  --遍历到的角色具有本技能、触发时机的角色不为遍历到的角色；
  --...
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target ~= player
    and not target:isNude() and data.num > 0
    and player:usedSkillTimes(self.name, Player.HistoryRound) < 1
  end,
  -- 反正是默认的，先这么放着
  -- on_cost = function(self, event, target, player, data)
  --   return true
  -- end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target ~= player then
      --doindicate的两个参数一个为integer，一个为table
      room:doIndicate(player.id, { target.id })
    end
    room:setPlayerMark(player, "@@v_keyu_used-round", 1)
    if not target:isNude() then
      local id = room:askForCardChosen(player, target, "he", self.name)
      local card = Fk:getCardById(id)
      target:showCards(card)
      room:moveCardTo(card, Player.Hand, player, fk.ReasonPrey, self.name, nil, true)
      if card and card.trueName == "slash" then
        room:loseHp(target, 1, self.name)
      end
    end
  end,
}

--------------------------------------------------
--纤柔
--FIXME:流失体力不触发
--------------------------------------------------

local v_xianrou_prohibit = fk.CreateProhibitSkill{
  name = "#v_xianrou_prohibit",
  --闪电这个版本还是能挂你脑门上的。
  is_prohibited = function(self, from, to, card)
    if to:hasSkill("v_xianrou") and from ~= to and card.suit == Card.Spade then
      return true
    end
  end,
}
local v_xianrou = fk.CreateTriggerSkill{
  name = "v_xianrou",
  --赋予防御型技能定义
  anim_type = "defensive",
  --技能为锁定技，满足条件后强制发动
  frequency = Skill.Compulsory,
  --时机：阶段变化时
  events = {fk.Damaged},
  --使用条件：
  --触发时机的角色为遍历到的角色、遍历到的角色具有本技能；
  --受到的伤害大于0，造成伤害的角色存在且存活，造成伤害的角色不为遍历到的角色。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) 
    and data.damage > 0 and data.from and data.from:isAlive()
    and data.from ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = data.from
    local prompt = "v_xianrou_ask:"..player.id
    --doindicate的两个参数一个为integer，一个为table
    room:doIndicate(player.id, { tar.id })
    -- 这里原版存在一个caneffect询问
    local card = room:askForCard(tar, 1, 1, true, self.name, true, ".|.|spade", prompt)[1]
    if card then
      --交牌
      room:moveCardTo(card, Player.Hand, player, fk.ReasonGive, self.name, nil, true)
    else
      --奶奶滴你为什么不触发？
      room:loseHp(tar, 1, self.name)
    end
  end,
}

v_xianrou:addRelatedSkill(v_xianrou_prohibit)

--------------------------------------------------
--芳乃推
--------------------------------------------------

local fangnaitui_yinyangmeiying = General(extension, "fangnaitui_yinyangmeiying", "individual", 3, 3, General.Bigender)
fangnaitui_yinyangmeiying:addSkill(v_keyu)
fangnaitui_yinyangmeiying:addSkill(v_xianrou)

Fk:loadTranslationTable{
	["fangnaitui_yinyangmeiying"] = "芳乃推",
	["&fangnaitui_yinyangmeiying"] = "芳乃推",
	["#fangnaitui_yinyangmeiying"] = "阴阳魅影",
	["$fangnaitui_yinyangmeiying"] = "简单",
	["designer:fangnaitui_yinyangmeiying"] = "夜玥紫英",
	["cv:fangnaitui_yinyangmeiying"] = "",
	["illustrator:fangnaitui_yinyangmeiying"] = "",
	["~fangnaitui_yinyangmeiying"] = "",
	["v_keyu"] = "渴欲",
	["@@v_keyu_used-round"] = "渴欲已使用",
	[":v_keyu"] = "每轮限一次，一名其他角色回复体力后，你可以<font color='#A9A9A9'>发动此技能</font>，展示并获得其一张牌，若之为【杀】则其失去1点体力。",
	["$v_keyu"] = "",
	["v_xianrou"] = "纤柔",
	["#v_xianrou_prohibit"] = "纤柔",
	[":v_xianrou"] = "锁定技，你不是其他角色使用黑桃牌的合法目标。你受到来自其他角色的伤害后，其须交给你一张黑桃牌，否则失去1点体力。",
	["$v_xianrou"] = "",
	["v_xianrou_ask"] = "请将一张黑桃牌交给 %src ，否则你失去1点体力",
}

--------------------------------------------------
--轮转
--------------------------------------------------

local v_lunzhuan = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_lunzhuan",
  --(非必要）赋予特殊型技能定义
  anim_type = "special",
  --时机：受到伤害时，造成伤害时
  events = {fk.DamageInflicted,fk.DamageCaused},
  --触发条件：
  --触发时机的角色为遍历到的角色、遍历到的角色具有本技能、造成的伤害大于0。
  --···
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name) and
      data.damage > 0) then return false end
    if event == fk.DamageInflicted then
      local room = player.room
      return room:getTag("RoundCount") >= 3
    end
    return true
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = nil
    if event == fk.DamageInflicted then
      prompt = "v_lunzhuan_damaged_choice"
    elseif event == fk.DamageCaused then
      prompt = "v_lunzhuan_damage_choice::"..data.to.id
    end
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      local roundcount = room:getTag("RoundCount")
      if roundcount - 3 < 0 then roundcount = 0
      elseif roundcount - 3 >= 0 then roundcount = roundcount - 3 end
      room:setTag("RoundCount", roundcount)
      local pls = room.players
      --为全体玩家更新轮数
      for _,p in ipairs(pls) do
        p:doNotify("UpdateRoundNum", roundcount or 0)
      end
      room:sendLog{
        type = "#v_minusround",
        arg = self.name,
        arg2 = room:getTag("RoundCount"),
      }
    elseif event == fk.DamageCaused then
      room:setTag("RoundCount", room:getTag("RoundCount") + 1)
      local pls = room.players
      --为全体玩家更新轮数
      for _,p in ipairs(pls) do
        p:doNotify("UpdateRoundNum", room:getTag("RoundCount") or 0)
      end
      room:sendLog{
        type = "#v_addround",
        arg = self.name,
        arg2 = room:getTag("RoundCount"),
      }
    end
    return true
  end,
}
  
--------------------------------------------------
--天怒
--------------------------------------------------
  
local v_tiannu_buff = fk.CreateTargetModSkill{
  name = "#v_tiannu_buff",
  --存在天怒额外出杀标记
  -- residue_func = function(self, player, skill, scope, card)
  --   if player:getMark("@v_tiannu_time-turn") > 0 then
  --     return player:getMark("@v_tiannu_time-turn")
  --   end
  -- end,
  --存在天怒额外目标标记
  --铁锁的问题和天怒无关（乐）
  extra_target_func = function(self, player, skill, card)
    if player:getMark("@v_tiannu_target-turn") > 0 and skill.trueName == "slash_skill" then
      -- local cards = card:isVirtual() and card.subcards or {card.id}
      return player:getMark("@v_tiannu_target-turn")
    end
  end,
}
local v_tiannu = fk.CreateTriggerSkill{
  name = "v_tiannu",
  --赋予进攻型技能定义
  anim_type = "offensive",
  mute = true,
  --时机：阶段开始时，轮次开始时，额定摸牌时，指定目标时
  events = {fk.RoundStart, fk.EventPhaseStart, fk.DrawNCards, fk.TargetSpecified},
  --触发条件（已完成）：
  --  触发时机的角色为遍历到的角色。
  --  阶段开始时：
  --    遍历到的角色存在此技能；遍历到的角色处于准备阶段；存在天怒标记
  --  轮次开始时：
  --    遍历到的角色存在此技能；
  --  额定摸牌时：
  --    存在天怒摸牌标记
  --  ···
  can_trigger = function(self, event, target, player, data)
    if not target == player then return false end
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self.name) 
        and player.phase == Player.Start
        and player:getMark("@v_tiannu") > 1
    --满足技能发动要求后，锁定发动。
    elseif event == fk.RoundStart then
      return player:hasSkill(self.name)
    elseif event == fk.DrawNCards then
      return target == player and player:getMark("@v_tiannu_draw-turn") > 0
    elseif event == fk.TargetSpecified then
      return target == player and player:getMark("@v_tiannu_time-turn") > 0
        and data.card.trueName == "slash"
        and data.firstTarget
        -- and data.card.id > 0
    end
  end,
  --使用条件（初步完成）：
  --  阶段开始时：
  --    询问是否发动，如果是，则发动
  --  轮次开始时：
  --    锁定发动；
  --  额定摸牌时：
  --    锁定发动；
  on_cost = function(self, event, target, player, data)
    --确认是否发动技能。
    if event == fk.EventPhaseStart then
      local room = player.room
      --拼提示字符串
      --目前prompt不支持arg3，血崩。
      local X = player:getMark("@v_tiannu")
      local choice = function (X)
        if X >= 8 then 
          -- return {3, math.ceil(X / 5.0), math.ceil(X / 8.0), math.ceil(X / 40.0)}
          return {3, math.ceil(X / 5.0), math.ceil(X / 8.0), nil}
        elseif X >= 4 then return {2, math.ceil(X / 5.0), math.ceil(X / 8.0), nil} end
        return {1, math.ceil(X / 5.0), nil, nil}
      end
      local prompt = "v_tiannu_choice_" .. choice(X)[1] .. "::"
      local times = choice(X)[1]
      if times > 2 then times = 2 end
      for i = 1, times do
        -- local num = function (i)
        --   if i ~= 1 then return i end
        --   return 1
        -- end
        local ar = ":" .. choice(X)[i+1]
        -- if num(i) > 1 then ar = ar .. num(i) end
        prompt = prompt .. ar
      end
      if room:askForSkillInvoke(player, self.name, data, prompt) then
        return true
      end
    --满足技能发动要求后，锁定发动。
    else
      return true
    end
  end,
  --使用效果（未完成）：
  --  阶段开始时：
  --    归零天怒标记；根据三种情况获取三种天怒标记
  --  轮次开始时：
  --    根据当前轮次为player增加天怒标记；
  --  额定摸牌时：
  --    根据标记数增加额定摸牌数；
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:broadcastSkillInvoke(self.name, -1)
      room:notifySkillInvoked(player, self.name)
      -- room:delay(2700)
      local X = player:getMark("@v_tiannu")
      room:setPlayerMark(player, "@v_tiannu", 0)
      if X >= 8 then room:setPlayerMark(player, "@v_tiannu_time-turn", math.ceil(X / 40.0)) end
      if X >= 4 then room:setPlayerMark(player, "@v_tiannu_target-turn", math.ceil(X / 8.0)) end
      if X >= 2 then room:setPlayerMark(player, "@v_tiannu_draw-turn", math.ceil(X / 5.0)) end
    elseif event == fk.RoundStart then
      room:addPlayerMark(player, "@v_tiannu", room:getTag("RoundCount"))
    elseif event == fk.DrawNCards then
      data.n = data.n + player:getMark("@v_tiannu_draw-turn")
    elseif event == fk.TargetSpecified then
      local room = player.room
      -- room:setEmotion(player, "./packages/vupslash/image/anim/v_shenban")
      local tarold = AimGroup:getAllTargets(data.tos)
      local tarnew = {}
      for _, p in ipairs(tarold) do
        TargetGroup:pushTargets(data.targetGroup, p)
        table.insert(tarnew, p)
        for i = 1, player:getMark("@v_tiannu_time-turn") do
          table.insert(tarnew, p)
        end
      end
      --注释：发log用的to是一维数组，而tos是二维数组
      if not data.card:isVirtual() then
        room:sendLog{
          type = "#v_changetarget_log",
          from = player.id,
          to = tarnew,
          arg = self.name,
          card = { data.card.id },
        }
      elseif data.card:isVirtual() then
        room:sendLog{
          type = "#v_changetarget_virtual_log",
          from = player.id,
          to = tarnew,
          arg = self.name,
          arg2 = data.card:toLogString(),
        }
      end
    end
  end,
}
v_tiannu:addRelatedSkill(v_tiannu_buff)

--------------------------------------------------
--映光AR5840
--------------------------------------------------

Fk:loadTranslationTable{
	["yingguangAR5840_wujiujiusi"] = "映光AR5840",
	["&yingguangAR5840_wujiujiusi"] = "映光AR5840",
	["#yingguangAR5840_wujiujiusi"] = "无咎久思",
	["$yingguangAR5840_wujiujiusi"] = "萌新",
	["designer:yingguangAR5840_wujiujiusi"] = "映光AR5840",
	["cv:yingguangAR5840_wujiujiusi"] = "",
	["illustrator:yingguangAR5840_wujiujiusi"] = "",
	["~yingguangAR5840_wujiujiusi"] = "",
	["v_lunzhuan"] = "轮转",
	[":v_lunzhuan"] = "当你造成/受到伤害时，你可以令游戏轮次+1/-3，防止此伤害。",
	["v_lunzhuan_damage_choice"] = "你可以令游戏轮次+1，防止此次对 %dest 造成的伤害",
	["v_lunzhuan_damaged_choice"] = "你可以令游戏轮次-3，防止此次自身受到的伤害",
	["v_tiannu"] = "天怒",
	["@v_tiannu"] = "怒",
	["@v_tiannu_draw-turn"] = "摸牌+",
	["@v_tiannu_target-turn"] = "额外目标+",
	["@v_tiannu_time-turn"] = "额外结算+",
	[":v_tiannu"] = "锁定技，轮次开始时，获得x个“怒”标记（x为当前轮次数）；"..	
	"<br/>准备阶段，你可以弃置所有标记，你获得以下效果直至回合结束:"..
	"<br/>标记>=2 你的额定摸牌数+x/5（向上取整）"..
	"<br/>标记>=4 你使用的【杀】可以额外指定x/8名目标（向上取整）"..
	"<br/>标记>=8 你使用的【杀】额外结算x/40次（向上取整）",
	-- "<br/>大于等于4 你使用的非转化的【杀】可以额外指定x/8名目标（向上取整）"..
	-- "<br/>大于等于8 你使用的非转化的【杀】额外结算x/40次（向上取整）",
	--目前prompt不支持arg3，血崩。
	["v_tiannu_choice_1"] = "你可以弃置所有标记，获得以下效果："..
	"<br/>你的额定摸牌数+ %arg ；",
	["v_tiannu_choice_2"] = "你可以弃置所有标记，获得以下效果："..
	"<br/>你的额定摸牌数+ %arg ；"..
	"<br/>你使用的【杀】可以额外指定 %arg2 名目标",
	-- ["v_tiannu_choice_3"] = "你可以弃置所有标记，获得以下效果："..
	-- "<br/>你的额定摸牌数+ %arg ；"..
	-- "<br/>你使用的杀可以额外指定 %arg2 名目标；"..
	-- "<br/>你使用的杀额外结算 %arg3 次",
	["v_tiannu_choice_3"] = "你可以弃置所有标记，获得以下效果："..
	"<br/>你的额定摸牌数+ %arg ；"..
	"<br/>你使用的【杀】可以额外指定 %arg2 名目标；"..
	"<br/>你使用的【杀】可以额外结算至少1次",
}

--------------------------------------------------
--附身
--1. 需要为extra_turn的tag处理做额外skill，以及技能发动判定也要注意
--2. 这个版本只能拿到两张角色牌上的技能
--------------------------------------------------

local v_fushen_invalidity = fk.CreateInvaliditySkill {
  name = "#v_fushen_invalidity",
  invalidity_func = function(self, from, skill)
    return from:getMark("@@v_fushen_target") > 0
      and not skill.attached_equip
  end
}

local v_fushen = fk.CreateTriggerSkill{
  --（刚需）技能认证名
  name = "v_fushen",
  --(非必要）赋予特殊型技能定义
  anim_type = "special",
  mute = true,
  frequency = Skill.Limited,
  --时机：阶段开始时，阶段变化时
  events = {fk.EventPhaseStart,fk.EventPhaseEnd,fk.EventPhaseChanging},
  --触发条件：
  --（通用）触发时机的角色为遍历到的角色（已完成）
  --（阶段开始时）遍历到的角色处于Notactive阶段、遍历到的角色存在invoke标记、（已完成）
  --             遍历到的角色不处于extra_turn
  --             （目前做不到，建议以后触发额外回合的时候做个额外mark陪着···）。
  --（阶段变化时）遍历到的角色存在invoking标记、遍历到的角色处于Notactive阶段。
  --（阶段变化时）遍历到的角色尚未使用过技能、遍历到的角色将进入出牌阶段、遍历到的角色存在出牌阶段。（已完成）
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self.name)) then return false end
    if event == fk.EventPhaseStart then
      return player.phase == Player.NotActive and player:getMark("v_fushen_invoke") > 0
    elseif event == fk.EventPhaseEnd then
      return 
        player:getMark("v_fushen_invoking") > 0 
        and player.phase == Player.Finish
    elseif event == fk.EventPhaseChanging then
      return
        player:usedSkillTimes(self.name, Player.HistoryGame) == 0 
        and data.to == Player.Play and VslUtil.exist_or_not(player, Player.Play)
    end
  end,
  --使用条件：（已完成）
  --（阶段开始时）消除invoke标记，给定范围，选择玩家，如果存在，return true。
  --（阶段结束时）return true。
  --（阶段变化时）askforskillinvoke。
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:setPlayerMark(player, "v_fushen_invoke", 0)
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        --后续可以在这里筛选caneffect角色。
        table.insert(targets, p.id)
      end

      if #targets > 0 then
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#v_fushen_target_choose", self.name, false)[1]
        if to then
          self.cost_data = to
          return true
        end
      end
    elseif event == fk.EventPhaseEnd then
      return true
    elseif event == fk.EventPhaseChanging then
      if room:askForSkillInvoke(player, self.name, data) then
        return true
      end
    end
  end,
  --使用效果：
  --（阶段开始时）发送附身信息等；换位置；获得对方技能；获得额外回合；
  -- PS:这个阶段你要是把对面扬了，直接报错，然后这个角色没了，但你依然可以打她。
  --（阶段结束时）发送结束附身信息；换回来；
  --（阶段变化时）失去附身未使用标记；获得invoke标记；跳过出牌阶段。
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local to = room:getPlayerById(self.cost_data)
      room:setPlayerMark(player, "v_fushen_to", self.cost_data)
      room:setPlayerMark(player, "v_fushen_invoking", 1)
      local skills = {}
      room:sendLog{
        type = "#v_fushen_log",
        from = player.id,
        to = {to.id},
        arg = self.name,
      }
      --这里看情况决定要不要写指示线
      if player ~= to then
        --doindicate的两个参数均为integer类型，一般为角色id
        room:doIndicate(player.id, { to.id })
      end
      room:notifySkillInvoked(player, self.name)
      VslUtil.swap_player(player, to, self.name)
      -- room:swapSeat(player, to)
      room:setPlayerMark(player, "@@v_fushen_using", 1)
      room:setPlayerMark(to, "@@v_fushen_target", 1)
      --这里需要把主将副将自己有的技能排除出去，免得回来之后技能没了
      for _, skill_name in ipairs(Fk.generals[to.general]:getSkillNameList()) do
        if (
          not Fk.skills[skill_name].lordSkill or 
          not Fk.skills[skill_name].frequency == Skill.Limited
          or not Fk.skills[skill_name].frequency == Skill.Wake) 
          and not table.find(Fk.generals[player.general]:getSkillNameList(), 
          function(skill_name_player)
            return skill_name_player == skill_name
          end
        ) then
          print(skill_name)
          table.insertIfNeed(skills, skill_name)
        end
      end
      if target.deputyGeneral and target.deputyGeneral ~= "" then
        for _, skill_name in ipairs(Fk.generals[to.deputyGeneral]:getSkillNameList()) do
          if (
            not Fk.skills[skill_name].lordSkill or 
            not Fk.skills[skill_name].frequency == Skill.Limited or 
            not Fk.skills[skill_name].frequency == Skill.Wake
            ) 
          and not table.find(Fk.generals[player.general]:getSkillNameList(), 
            function(skill_name_player)
              return skill_name_player == skill_name
            end
          ) then
            table.insertIfNeed(skills, skill_name)
          end
        end
      end
      if #skills > 0 then
        room:setPlayerMark(player, "v_fushen_skills", skills)
        room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, true, false)
      end
      player:gainAnExtraTurn()
    elseif event == fk.EventPhaseEnd then
      room:setPlayerMark(player, "v_fushen_invoking", 0)
      local to = room:getPlayerById(player:getMark("v_fushen_to"))
      room:sendLog{
        type = "#v_fushen_end_log",
        from = player.id,
        to = {to.id},
        arg = self.name,
      }
      if to:isAlive() and player:isAlive() then
        VslUtil.swap_player(player, to, self.name)
      else
        room:swapSeat(player, to)
      end
      room:setPlayerMark(player, "@@v_fushen_using", 0)
      room:setPlayerMark(to, "@@v_fushen_target", 0)
      local skills = player:getMark("v_fushen_skills")
      if skills ~= 0 and #skills > 0 then
        room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil, true, false)
      end
    elseif event == fk.EventPhaseChanging then
      room:setPlayerMark(player, "@@v_fushen", 0)
      room:setPlayerMark(player, "v_fushen_invoke", 1)
      return true
    end
  end,
}

v_fushen:addRelatedSkill(v_fushen_invalidity)

-- 加载本包的翻译包(load translations of this package)，这一步在本文档的最后进行。
-- dofile "packages/vupslash/i18n/init.lua"

-- return { extension } 

return extension
